[Bug]: Pack target is causing unnecessary project evaluations which noticeably slows down a project's build
#11.530 aperta il 28 gen 2022
Metriche repository
- Star
- (1459 star)
- Metriche merge PR
- (Merge medio 464g 23h) (1 PR mergiata in 30 g)
Descrizione
NuGet Product Used
dotnet.exe
Product Version
6.0.100
Worked before?
No response
Impact
It bothers me. A fix would be nice
Repro Steps & Context
When building a .NET project which sets the GeneratePackOnBuild switch or when invoking the Pack target, NuGet calls into the underlying projects via an MSBuild Exec task (i.e. based on the project.assets.json data) and set BuildProjectReferences=false as a global property. Because of the global property, additional project evaluations are triggered which slow down the overall build.
- https://github.com/NuGet/NuGet.Client/blob/fd00d6dd248ed74c2fe006bbd4b8ca53d8ebdeac/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets#L328-L337
- https://github.com/NuGet/NuGet.Client/blob/fd00d6dd248ed74c2fe006bbd4b8ca53d8ebdeac/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets#L384-L416
This is especially noticeable when projects multi-target. As an example, let's consider a project "A" that multi-targets for net6.0;net5.0;netstandard2.0;net48. Based on the the described issue, the evaluations double from 5 to 10:
Before:
Outer build net6.0;net5.0;netstandard2.0;net48
Inner build net6.0
Inner build net5.0
Inner build netstandard2.0
Inner build net48
After:
Outer build net6.0;net5.0;netstandard2.0;net48
Inner build net6.0
Inner build net5.0
Inner build netstandard2.0
Inner build net48
Outer build net6.0;net5.0;netstandard2.0;net48 with additional BuildProjectReferences global property
Inner build net6.0 with additional BuildProjectReferences global property
Inner build net5.0 with additional BuildProjectReferences global property
Inner build netstandard2.0 with additional BuildProjectReferences global property
Inner build net48 with additional BuildProjectReferences global property
Shouldn't it be possible to avoid these extra evaluations by sequencing the gathering of the required data into the already running outer build, which runs without the BuildProjectReferences global property?
Verbose Logs
No response