Search code examples
c#asp.netmsbuildnugetcsproj

Transitive SDK project references in ASP.NET projects


I'm in the process of trying to migrate various C# library projects in a solution to use the new SDK (VS2017+) format. The solution also contains a couple of ASP.NET projects that need to reference these libraries.

I'm aware that I can't update the ASP.NET projects to use the new SDK-based build system at this time, but I have modified them to use <PackageReference/> entries instead of a packages.config file for the top-level NuGet references.

There are a number of dependency scenarios in the solution that are similar to the following:

ASP.NET Project
  --> Top.Level.Package (NuGet)
  --> Project A (csproj)
    --> Some.Package (NuGet)
    --> Project C (csproj)
      --> Some.Other.Package (NuGet)
  --> Project B (csproj)
    --> Project C (csproj)
      --> Some.Other.Package (NuGet)

I.e. an ASP.NET project references a top-level NuGet package, Project A and Project B; Project A references a NuGet package and Project C; Project B references Project C; and Project C references a NuGet package. All of the non-ASP.NET projects have been modified to be SDK projects using <PackageReference/> entries for NuGet package references, and all transitive dependencies flow between them without any issue.

The problem that I am running into is that, when I build the ASP.NET application, MSBuild is correctly copying the assemblies for Project A and Project B, and the assemblies from both the top-level and transitive NuGet package references into the bin folder, but it is not copying the output of the transitive Project C, which is required by both Project A and Project B.

Is there a straightforward way around this, beyond adding top-level project references in the ASP.NET projects to the "missing" projects?


Solution

  • This is because the ASP.NET Project does not (and currently can not) support the SDK-style project type.

    SDK-style projects actively query project references for further dependencies. Since the ASP.NET project does not do that, you have to add the reference yourself. (Or add the needed MSBuild logic yourself as seen in this file - search for IncludeTransitiveProjectReferences, but I can't really recommend that approach as it may conflict with VS updates)