Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CPM] dotnet add package with --no-restore causes NU1008 #12552

Open
sbazant opened this issue Apr 24, 2023 · 3 comments
Open

[CPM] dotnet add package with --no-restore causes NU1008 #12552

sbazant opened this issue Apr 24, 2023 · 3 comments
Labels
Area:RestoreCPM Central package management Functionality:Restore Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Product:dotnet.exe Type:DCR Design Change Request

Comments

@sbazant
Copy link

sbazant commented Apr 24, 2023

NuGet Product Used

dotnet.exe

Product Version

8.0.100-preview.3.23178.7

Worked before?

No response

Impact

I'm unable to use this version

Repro Steps & Context

  1. Create empty project with dotnet new console
  2. Add Directory.Packages.props file with
<Project>
  <PropertyGroup>
    <ManagePackageVersionsCentrally>true</ManagePackageVersionsCentrally>
  </PropertyGroup>
</Project>
  1. Add package with --no-restore option i.e. dotnet add package Newtonsoft.Json --no-restore
  2. 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).
@sbazant
Copy link
Author

sbazant commented 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
Copy link
Member

zivkan commented Apr 28, 2023

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.

@zivkan zivkan added Product:dotnet.exe Type:DCR Design Change Request Area:RestoreCPM Central package management and removed Triage:Untriaged Type:Bug labels Apr 28, 2023
@jeffkl jeffkl added Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Pipeline:Icebox labels May 4, 2023
@jeffkl jeffkl changed the title [CPVM] dotnet add package with --no-restore causes NU1008 [CPM] dotnet add package with --no-restore causes NU1008 May 4, 2023
@jeffkl
Copy link
Contributor

jeffkl commented 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:RestoreCPM Central package management Functionality:Restore Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Product:dotnet.exe Type:DCR Design Change Request
Projects
None yet
Development

No branches or pull requests

4 participants