Repository navigation
CpsPackageReferenceProject uses PackageSpecFactory - #7379
Merged
Merged
Conversation
zivkan
commented
May 8, 2026
jeffkl
previously approved these changes
May 11, 2026
jeffkl
left a comment
Contributor
There was a problem hiding this comment.
Looks right, but there are lots of changes. Are any of the test failures related?
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates Visual Studio CPS PackageReference restore nomination to build PackageSpec instances via PackageSpecFactory, aligning it with other restore entry points and enabling consistent behavior behind an environment-variable switch.
Changes:
- Add
PackageSpecFactory.GetIntermediatePackageSpec(...)+PackageSpecFactory.ApplySettings(...)to support caching an “intermediate”PackageSpecand applying currentnuget.configsettings later. - Update
VsSolutionRestoreServiceto optionally generate nominations viaPackageSpecFactory(opt-out viaNUGET_USE_NEW_PACKAGESPEC_FACTORY=false) and add a VS-nomination-to-IProjectadapter layer. - Expand
VsSolutionRestoreServiceTeststo run most scenarios in both code paths (PackageSpecFactory enabled/disabled) and adjust the test nomination builder to better mimic MSBuild behavior.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/NuGet.Clients.Tests/NuGet.SolutionRestoreManager.Test/VsSolutionRestoreServiceTests.cs | Parameterizes tests to validate both PackageSpecFactory and legacy nomination paths; adds env-var test wiring. |
| test/NuGet.Clients.Tests/NuGet.SolutionRestoreManager.Test/TestProjectRestoreInfoBuilder.cs | Adds common MSBuild-like properties and synthesizes ProjectReference FullPath metadata. |
| src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/PackageSpecFactory.cs | Introduces intermediate PackageSpec creation + settings application helpers and adjusts source/fallback-folder handling accordingly. |
| src/NuGet.Core/NuGet.Commands/PublicAPI/net8.0/PublicAPI.Unshipped.txt | Declares new public API surface for PackageSpecFactory.ApplySettings and GetIntermediatePackageSpec. |
| src/NuGet.Core/NuGet.Commands/PublicAPI/net472/PublicAPI.Unshipped.txt | Declares new public API surface for PackageSpecFactory.ApplySettings and GetIntermediatePackageSpec. |
| src/NuGet.Core/NuGet.Build.Tasks.Console/TargetFrameworkAdapter.cs | Enables nullable and updates ITargetFramework.GetProperty signature to nullable. |
| src/NuGet.Clients/NuGet.SolutionRestoreManager/VsSolutionRestoreService.cs | Adds env-var controlled switch and routes nomination spec creation through PackageSpecFactory via adapters. |
| src/NuGet.Clients/NuGet.SolutionRestoreManager/VSNominationUtilities.cs | Widens helper visibility needed by adapters (internal). |
| src/NuGet.Clients/NuGet.SolutionRestoreManager/PackageSpecAdapter/OuterBuildAdapter.cs | New adapter to represent “outer build” behavior for CPS nominations. |
| src/NuGet.Clients/NuGet.SolutionRestoreManager/PackageSpecAdapter/NominationProjectAdapter.cs | New adapter implementing IProject over VS nomination objects. |
| src/NuGet.Clients/NuGet.SolutionRestoreManager/PackageSpecAdapter/ItemAdapter.cs | New adapter implementing IItem over VS reference items. |
| src/NuGet.Clients/NuGet.SolutionRestoreManager/PackageSpecAdapter/InnerBuildAdapter.cs | New adapter implementing ITargetFramework over per-TFM nomination data. |
| src/NuGet.Clients/NuGet.SolutionRestoreManager/NuGet.SolutionRestoreManager.csproj | Includes HashCodeCombiner shared source for adapter hashing logic. |
| src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/Projects/CpsPackageReferenceProject.cs | Switches settings application from VSRestoreSettingsUtilities to PackageSpecFactory.ApplySettings. |
| src/NuGet.Clients/NuGet.PackageManagement.VisualStudio/GlobalSuppressions.cs | Removes suppression for a deleted helper method. |
Member
Author
zivkan
marked this pull request as draft
May 12, 2026 01:18
zivkan
force-pushed
the
dev-zivkan-PackageSpecFactory-CPS
branch
from
May 13, 2026 06:19
470fc90 to
55e1a61
Compare
zivkan
marked this pull request as ready for review
May 13, 2026 10:59
nkolev92
reviewed
May 13, 2026
nkolev92
approved these changes
May 14, 2026
Copilot AI
added a commit
that referenced
this pull request
May 15, 2026
This reverts commit 4286cb0. Co-authored-by: nkolev92 <[email protected]>
nkolev92
added a commit
that referenced
this pull request
May 16, 2026
…7397) This reverts commit 4286cb0. Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: nkolev92 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug
working towards: NuGet/Home#14160
Description
CpsPackageReferenceProject now joins LegacyPackageReferenceProject and MSBuildStaticGraphRestore in using PackageSpecFactory. These only leaves "normal" msbuild restore not using PackageSpecFactory yet.
Since the point of PackageSpecFactory is to make all PackageReference restores works the same way, it would have been ideal if the only changes required were adding the environment variable check to opt-out of PackageSpecFactory, and making existing tests check both PackageSpecFactory enabled and disabled code paths. Unfortunately, PackageSpecFactory needed substantial changes, for the following reason:
PackageSpec, and then each time our VSPackageReferenceProjectwants to get thePackageSpec,CpsPackageReferenceProjectcan clone the intermediatePackageSpecand then modify it with the current nuget.config settings.PackageSpecthat are modified when applying nuget.config settings are package sources, fallback folders, and the global packages folder. For sources and fallback folders, it's possible to either provide locations in addition to the nuget.config values, or override anything in nuget.config and use only the values from the project properties.LegacyPackageReferenceProjectwould benefit from the same thing, except legacy projects don't have a way to notify NuGet when properties or items change. Therefore,LegacyPackageReferenceProjecthas to regenerate the fullPackageSpecevery time, so there's no benefit to having the intermediatePackageSpec.PackageSpec.NullSettingsdoesn't work because sometimes nuget.config sources are used in addition to project property sources, but sometimes not.Otherwise, this feature has very minimal impact on existing code. The changes to VsSolutionRestoreServiceTests.cs is a lot of lines, but it's only to enable all the tests to run on both the PackageSpecFactory and legacy code paths, to make sure they both work the same, with just one exception.
PR Checklist
Link to an issue or pull request to update docs if this PR changes settings, environment variables, new feature, etc.Customers will only notice if there are bugs, in which case we should fix the bugs. No expected change in behavior.