NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 253 forks source link

[DCR]: Dependent project does not generate nuget package when multiple TFMs #12119

Open odalet opened 2 years ago

odalet commented 2 years ago

NuGet Product(s) Affected

dotnet.exe

Current Behavior

Note that I first raised this issue in the msbuild repository but it was suggested to me this should rather belong here. So Here it goes.

Consider this scenario:

Now, let's dotnet build Lib1.csproj:

NB: this does not happen when building the solution in VS

Desired Behavior

Lib2.nupkg should be generated

I understand it is probably not straightforward, but according to the least surprise principle, I think it'd be desirable.

Additional Context

Steps to Reproduce

I also attached the corresponding binlog (build in release configuration this time): binlog.zip

Analysis

I've skimmed through the binlog and I think it boils down to IsInnerBuild = truepreventing Lib2's nuget package from being generated. Here is what I guess happens:

Versions & Configurations

jeffkl commented 2 years ago

We're not convinced this should be changed at this time. The .NET SDK is currently in charge of dispatching builds for projects and currently it calls the "outer" build of Lib1 which dispatches two "inner" builds for Lib1, one for each target framework. Each inner build of Lib1 then dispatches an inner build to Lib2 for that specific target framework to fulfill the project reference. Once the outer build of Lib1 is complete, NuGet then calls pack on the entry project since GeneratePackageOnBuild is set to true. NuGet would need to then dispatch outer builds on all dependent projects so they could be packed.

However, we see dotnet build with GeneratePackageOnBuild to be the same as running dotnet pack. The pack gesture in our opinion means an operation that should be run on the entry project only. I'm not convinced that packing the project in the current directory and all transitive dependencies is what people expect to happen.

This works already when you pack a Visual Studio solution file because the .NET SDK dispatches all of the outer builds since that is what a solution file is for, indicating all of the projects to build as a unit. In this case, it makes sense that pack would run for each project.

We'll leave this issue open for now so the community can comment. Please leave feedback or upvote if you feel the design should change. One way I envision this working is a new property like PackTransitive would be added and NuGet would then dispatch Pack target builds to all of the project references first. But this might have some side effects that cause other issues since its a behavior change.