NuGet / Home

Repo for NuGet Client issues
Other
1.49k stars 249 forks source link

Package installation mixes versions after `nuget install packages.config -ExcludeVersion` #13457

Open hickford opened 1 month ago

hickford commented 1 month ago

NuGet Product Used

NuGet.exe

Product Version

6.9.1.3

Worked before?

No response

Impact

It's more difficult to complete my work

Repro Steps & Context

  1. Create packages.config:
<packages>
  <package id="NUnit" version="3.0.0" />
</packages>
  1. Run nuget install packages.config -ExcludeVersion

  2. Edit packages.config:

<packages>
  <package id="NUnit" version="3.14.0" />
</packages>
  1. Run nuget install packages.config -ExcludeVersion

  2. Inspect NUnit folder. You'll find the installation is a mix of versions 3.0.0 and 3.14.0. Here's a comparison with Powershell's Get-FileHash

3ded35f5   NUnit\NUnit.nupkg  [3.0.0]                                                                                                 
78ac5a04   NUnit\lib\dotnet\nunit.framework.dll  [3.0.0]
538d1995   NUnit\lib\net20\nunit.framework.dll  [3.0.0]
06b1f4b7   NUnit\lib\net35\nunit.framework.dll  [3.14.0]
afac13bd   NUnit\lib\net40\nunit.framework.dll  [3.0.0]
b8b8eca8   NUnit\lib\net45\nunit.framework.dll  [3.0.0]
d0332e30   NUnit\lib\netstandard2.0\nunit.framework.dll  [3.14.0]
78ac5a04   NUnit\lib\portable-net45+win8+wp8+wpa81+Xamarin.Mac+MonoAndroid10+MonoTouch10+Xamarin.iOS10\nunit.framework.dll  [3.0.0]

3ded35f5   NUnit.3.0.0\NUnit.3.0.0.nupkg
78ac5a04   NUnit.3.0.0\lib\dotnet\nunit.framework.dll
538d1995   NUnit.3.0.0\lib\net20\nunit.framework.dll
afac13bd   NUnit.3.0.0\lib\net40\nunit.framework.dll
b8b8eca8   NUnit.3.0.0\lib\net45\nunit.framework.dll
78ac5a04   NUnit.3.0.0\lib\portable-net45+win8+wp8+wpa81+Xamarin.Mac+MonoAndroid10+MonoTouch10+Xamarin.iOS10\nunit.framework.dll

0ae3ffab   NUnit.3.14.0\NUnit.3.14.0.nupkg
06b1f4b7   NUnit.3.14.0\lib\net35\nunit.framework.dll
01445513   NUnit.3.14.0\lib\net40\nunit.framework.dll
1d88aadc   NUnit.3.14.0\lib\net45\nunit.framework.dll
d0332e30   NUnit.3.14.0\lib\netstandard2.0\nunit.framework.dll

It looks like old files aren't deleted or overwritten.

Verbose Logs

Restoring NuGet package NUnit.3.0.0.
Adding package 'NUnit.3.0.0' to folder 'C:\code\nuget-playground\pc'
Added package 'NUnit.3.0.0' to folder 'C:\code\nuget-playground\pc'

Restoring NuGet package NUnit.3.14.0.
Adding package 'NUnit.3.14.0' to folder 'C:\code\nuget-playground\pc'
Added package 'NUnit.3.14.0' to folder 'C:\code\nuget-playground\pc'
hickford commented 1 month ago

Without packages.config, upgrade works as expected:

nuget install NUnit -Version 3.0.0 -ExcludeVersion
nuget install NUnit -Version 3.14.0 -ExcludeVersion

Logs show that the old package is uninstalled:

Successfully uninstalled 'NUnit.3.0.0' from C:\code\nuget-playground\single-version
Adding package 'NUnit.3.14.0' to folder 'C:\code\nuget-playground\single-version'
Added package 'NUnit.3.14.0' to folder 'C:\code\nuget-playground\single-version'
Successfully installed 'NUnit 3.14.0' to C:\code\nuget-playground\single-version
nkolev92 commented 1 month ago

I don't really know if restoring from packages.config and ExcludeVersion are really expected to be combined.

Likely low impact, but we'd be happy to consider a fix.

hickford commented 1 month ago

@nkolev92 There's nothing in the docs to say you can't use packages.config and ExcludeVersion together https://learn.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-install

A GitHub code search for the combination has thousands of results https://github.com/search?q=ExcludeVersion+packages.config&type=code