You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[CPM] dotnet add package with --no-restore causes NU1008 #12552
Add package with --no-restore option i.e. dotnet add package Newtonsoft.Json --no-restore
Run restore dotnet restore
Verbose Logs
C:\repos\test>dotnet add package --no-restore Newtonsoft.Json
info : X.509 certificate chain validation will use the default trust store selected by .NET.
info : X.509 certificate chain validation will use the default trust store selected by .NET.
info : Adding PackageReference for package 'Newtonsoft.Json' into project 'C:\repos\test\test.csproj'.
warn : --no-restore|-n flag was used. No compatibility check will be done and the added package reference will be unconditional.
info : PackageReference for package 'Newtonsoft.Json' version '*' added to file 'C:\repos\test\test.csproj'.
C:\repos\test>dotnet restore
Determining projects to restore...
C:\repos\test\test.csproj : error NU1008: Projects that use central package version management should not define the version on the PackageReference items but on the PackageVersion items: Newtonsof
t.Json.
Failed to restore C:\repos\test\test.csproj (in 129 ms).
Note to whoever works on this: The way dotnet add package is designed is to add the package with the floating version *, restore, check what version was actually restored, then change the * to the actually-installed version. I can't remember if it does a second restore to make the assets file up to date.
The implementation could just use NuGet.Protocol.SourceRepository to query the sources to see what versions are available, and skip the first restore.
changed the title [-][CPVM] dotnet add package with --no-restore causes NU1008[/-][+][CPM] dotnet add package with --no-restore causes NU1008[/+]on May 4, 2023
Team Triage: CPM specifically does not support wildcards so at the very least we can block dotnet add package --no-restore with no version. At the moment, it appears that if you do specify a version, it does not update Directory.Packages.props.
Activity
sbazant commentedon Apr 24, 2023
My project is under CI/CD where coverlet is being injected as one of the steps, and this injection step breaks the build
zivkan commentedon Apr 28, 2023
Note to whoever works on this: The way
dotnet add packageis designed is to add the package with the floating version*, restore, check what version was actually restored, then change the*to the actually-installed version. I can't remember if it does a second restore to make the assets file up to date.The implementation could just use
NuGet.Protocol.SourceRepositoryto query the sources to see what versions are available, and skip the first restore.[-][CPVM] dotnet add package with --no-restore causes NU1008[/-][+][CPM] dotnet add package with --no-restore causes NU1008[/+]jeffkl commentedon May 4, 2023
Team Triage: CPM specifically does not support wildcards so at the very least we can block
dotnet add package --no-restorewith no version. At the moment, it appears that if you do specify a version, it does not updateDirectory.Packages.props.ezhdn commentedon Apr 7, 2025
Hi folks! Any good news on this issue or a possible workaround?
Fix --no-restore corrupting .csproj in CPM projects
Fix --no-restore corrupting .csproj in CPM projects (#713)
dotnet package add --no-restoreadds version to wrong file when used with Central Package Management (CPM) #14822 as a duplicate of this issueReport a failure when no central package entry could be updated
Fix multiline central package version updates (#783)