Skip to content

Re-implement Pack: reuse existing evaluations instead of forcing BuildProjectReferences=false - #7603

Merged
nkolev92 merged 3 commits into
NuGet:devfrom
baronfel:baronfel-dev-baronfel-fix-pack-item-collision
Jul 31, 2026
Merged

nkolev92 merged 3 commits into
NuGet:devfrom
baronfel:baronfel-dev-baronfel-fix-pack-item-collision

Conversation

@baronfel

@baronfel baronfel commented Jul 30, 2026 •

Copy link
Copy Markdown
Contributor

Bug

Fixes: NuGet/Home#11530

Description

Restores the Pack evaluation reuse introduced by NuGet.Client #7541 and temporarily reverted by NuGet.Client #7593, while fixing the item collision exposed by that reuse.

VMR build 1524269 and dotnet/dotnet #7907 failed while packing ASP.NET Core because NuGet Pack and ASP.NET Core both used the private item name _ProjectPathWithVersion. Once #7541 allowed existing project instances to be reused, consumer-created items remained on those instances. _GetProjectVersion then returned the accumulated entries, and PackTask failed when it created a dictionary keyed by project path.

This change renames NuGet's private _GetProjectVersion output to _ProjectReferenceWithVersion, isolating it from consumer-owned _ProjectPathWithVersion items and making project-instance reuse safe. Normal Pack calls reuse already-built project evaluations, while NoBuild=true still appends BuildProjectReferences=false for _GetFrameworkAssemblyReferences so referenced projects are not built during a no-build pack.

Following Nikolche's feedback on dotnet/dotnet #7952, this port does not add the synthetic collision test because the private-item rename makes that setup obsolete. It does retain the meaningful assertion adjustment in the existing include-source test: evaluation reuse may preserve additional source items, so the test verifies that every user-authored source is present without requiring the package to contain exactly four source entries.

Validation:

  • dotnet test test\NuGet.Core.FuncTests\Dotnet.Integration.Test\Dotnet.Integration.Test.csproj --no-restore --filter "FullyQualifiedName~PackCommand_IncludeSource_AddsSourceFiles|FullyQualifiedName~PackCommand_PackProject_ExactVersionOverrideProjectRefVersionInMsbuild" /bl:9.binlog — 6 passed, 0 failed.
  • dotnet format whitespace NuGet.sln --verify-no-changes --include test\NuGet.Core.FuncTests\Dotnet.Integration.Test\PackCommandTests.cs --verbosity diagnostic --binarylog 10.binlog — completed successfully.

PR Checklist

  • Meaningful title, helpful description and a linked NuGet/Home issue
  • Added tests
  • Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.

Restore Pack evaluation reuse while isolating _GetProjectVersion outputs from consumer-owned items. Preserve no-build behavior and update the include-source assertion for reused evaluations.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7f8abcb6-2d81-4392-b9e9-d5e61d4650c4
@dotnet-policy-service dotnet-policy-service Bot added the Community PRs created by someone not in the NuGet team label Jul 30, 2026
baronfel and others added 2 commits July 30, 2026 15:07
Keep the upstream port scoped to the Pack targets. The existing project-reference version tests cover the production change without modifying test sources.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 7f8abcb6-2d81-4392-b9e9-d5e61d4650c4
Evaluation reuse can retain additional source items, so assert that the user-authored sources are present without requiring an exact item count.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 7f8abcb6-2d81-4392-b9e9-d5e61d4650c4
@nkolev92

Copy link
Copy Markdown
Member

This probably needs the old title in the end.

@baronfel baronfel changed the title Fix Pack project-version item collision Re-implement Pack: reuse existing evaluations instead of forcing BuildProjectReferences=false Jul 30, 2026
@baronfel
baronfel marked this pull request as ready for review July 30, 2026 20:18
@baronfel
baronfel requested a review from a team as a code owner July 30, 2026 20:18
@baronfel
baronfel requested review from jebriede and zivkan July 30, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community PRs created by someone not in the NuGet team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Pack target is causing unnecessary project evaluations which noticeably slows down a project's build

2 participants