NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 253 forks source link

dotnet add command incorrect behaviou #12404

Open 0xF6 opened 1 year ago

0xF6 commented 1 year ago

NuGet Product Used

dotnet.exe

Product Version

dotnet --info
.NET SDK:
 Version:   7.0.102
 Commit:    4bbdd14480

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.25281
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.102\

Host:
  Version:      7.0.2
  Architecture: x64
  Commit:       d037e070eb

.NET SDKs installed:
  7.0.100 [C:\Program Files\dotnet\sdk]
  7.0.102 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Worked before?

No response

Impact

None

Repro Steps & Context

Describe the bug

Incorrect error when adding a package, provided that the project has a link to another project with the same name

I took the name Newtonsoft.Json as an example In my large project, I did not immediately understand what the problem was, because the error is not very informative. And I didn't find how to enable the detailed log I would like to have an error something like of "Package with 'Newtonsoft.Json' already referenced to this project" or something similar

To Reproduce

  1. Clone this repo
  2. Go to ./NuGetBugTest
  3. Execute command dotnet add package Newtonsoft.Json --version 13.0.2

Exception:

error: Value cannot be null. (Parameter 'path1')
  Determining projects to restore...
  Writing C:\Users\ls-mi\AppData\Local\Temp\tmpD16B.tmp
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:\git\NuGetBugTest\NuGetBugTest\NuGetBugTest.csproj'.
info : Restoring packages for C:\git\NuGetBugTest\NuGetBugTest\NuGetBugTest.csproj...
info : Package 'Newtonsoft.Json' is compatible with all the specified frameworks in project 'C:\git\NuGetBugTest\NuGetBugTest\NuGetBugTest.csproj'.
error: Value cannot be null. (Parameter 'path1')

Usage: NuGet.CommandLine.XPlat.dll package add [options]

Options:
  -h|--help               Show help information
  --force-english-output  Forces the application to run using an invariant, English-based culture.
  --package               Id of the package to be added.
  --version               Version of the package to be added.
  -d|--dg-file            Path to the dependency graph file to be used to restore preview and compatibility check.
  -p|--project            Path to the project file.
  -f|--framework          Frameworks for which the package reference should be added.
  -n|--no-restore         Do not perform restore preview and compatibility check. The added package reference will be unconditional.
  -s|--source             Specifies NuGet package sources to use during the restore.
  --package-directory     Directory to restore packages in.
  --interactive           Allow the command to block and require manual action for operations like authentication.
  --prerelease            Allows prerelease packages to be installed.

Verbose Logs

dotnet add not use verbose log D:
0xF6 commented 1 year ago

forwarded from https://github.com/dotnet/sdk/issues/30286