Search code examples
.net-corebuildmsbuilddependenciesteamcity

Problem referencing transitive dependencies when building a specific .NET Core project in TeamCity


I have a solution with multiple projects, the notable projects are:

  • ContractProject
  • DataProject
  • WebProject

WebProject is a .NET Core project, the other two are .NET Framework.

This is the file structure, including the csproj and sln files:

enter image description here

DataProject references Dapper, which is a NuGet package.

When attempting to run the build configuration in TeamCity, I get the following (slightly reduced, redacted) error:

DapperWorklistRepository.cs(4,7): error CS0246: The type or namespace name 'Dapper' could not be found (are you missing a using directive or an assembly reference?) [REDACTED_PATH_TO_DATAPROJECT_CSPROJ_FILE]
......
Build FAILED.
......
Process exited with code 1
Step Build (.NET Core (dotnet)) failed

This is my only build step (.NET Core):

enter image description here

Any idea what I'm doing wrong? I have a feeling it may be something to do with the web project not being able to reference the projects one level back? I have tried setting the required paths in many different ways with no avail.


Solution

  • I ended up figuring this out, implementing a bit of a hack of a solution.

    The problem lies in the fact that I'm referencing .NET Framework projects from a .NET Core project, and attempting to build them all in one step.

    The work around required two things:

    Firstly, I had to include a NuGet installer build step. I couldn't figure out how to target specifically .NET Framework projects (it doesn't support .NET Core), so I essentially duplicated the solution file, renamed it to NetCoreBuildHelper, and deleted the Web project reference. The reference remained in the original solution. I then referenced the new NetCoreBuildHelper solution in the NuGet Installer.

    Secondly, I had to create a .NET Framework MSBuild step, which built the other projects (DataProject and ContractProject), referencing the NetCoreBuildHelper solution.

    I'd love to hear responses to this if I could improve the solution, as it feels like a bit of a hack