'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 1:[1]

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

Solution 2:[2]

This question is on the older side - but I'm interested in knowing if you arrived at any more information.

To the best of my knowledge, .Net Framework and .Net Core are fundamentally different platforms, so they are not meant to be referenced by one other. .Net Standard projects however, are intended to be a vehicle for code sharing that both .Net Core and .Net Framework can reference, as long as the Standard version being targeted is the correct version. For example, .Net Framework 4.8 is, at most, .Net Standard 2.0 compatible. If the .Net Framework projects were class libraries, it might be worth migrating those to be .Net Standard projects, and reference them from your .Net Core project.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Jessica
Solution 2 iresearchhere