Repository navigation
Fix dotnet add package --no-restore ignoring Central Package Management - #7148
Merged
Merged
Conversation
…ment When --no-restore is passed, CPM detection is skipped because it relies on the DependencyGraphSpec built during restore. This causes a versioned PackageReference to be written directly to the .csproj, resulting in NU1008 on the next restore. Fix by checking the MSBuild-evaluated ManagePackageVersionsCentrally property, which is available via GetProject() without restore. Co-Authored-By: Claude Opus 4.6 <[email protected]>
zivkan
reviewed
Feb 19, 2026
AddPackageReference and AddPackageReferencePerTFM now determine CPM status from the project they already load, eliminating the separate IsCentralPackageManagementEnabled call that loaded the project a second time. This simplifies the API so callers don't need to pre-set VersionCentrallyManaged on LibraryDependency. Co-Authored-By: Claude Opus 4.6 <[email protected]>
VersionCentrallyManaged is init-only, so it cannot be assigned after construction. Move the CPM check into the private AddPackageReference method which reads it directly from the already-loaded Project object. Co-Authored-By: Claude Opus 4.6 <[email protected]>
|
Not stale, waiting for reviews |
Member
|
We normally wait for a re-request for review to know it's ready for another look. We'll take a look. |
jeffkl
approved these changes
Mar 2, 2026
This was referenced Mar 10, 2026
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
Fixes: NuGet/Home#12552
Description
When
--no-restoreis passed todotnet add packagein a CPM-enabled project, the command writes a versioned<PackageReference Version="...">directly to the .csproj, ignoring Central Package Management. This happens because CPM detection relies on theDependencyGraphSpecbuilt during restore, which--no-restoreskips. The result is NU1008 on the next restore.This fix adds a new
IsCentralPackageManagementEnabled()method toMSBuildAPIUtilitythat checks the MSBuild-evaluatedManagePackageVersionsCentrallyproperty (available viaGetProject()without restore), and setsVersionCentrallyManagedon theLibraryDependencyin the--no-restorepath. The existing downstream CPM handling then correctly produces a versionless<PackageReference>in the .csproj and a<PackageVersion>inDirectory.Packages.props.PR Checklist