NuGet 2.8.6 causing dependency on .NET 4.5+?

2020-07-12 23:57发布

问题:

Recently started getting errors on build machines using latest nuget.exe (2.8.6)

.nuget\nuget restore MySolution.sln

Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Exact same command / source tree restores perfectly using nuget.exe 2.8.5

Build machine is Windows 2008 R2, .NET 4.0 (no 4.5 updates allowed on this build image) and VS 2010. Basically, we have a number of build machines that are configured for specific combinations (Windows, .NET, Visual Studio).

It feels like the 2.8.6 build took a dependency on .NET 4.5 that breaks on machines without it.

回答1:

I raised this as an issue but, from what I have been told, there are no plans to fix it: https://github.com/NuGet/Home/issues/1611

The workaround is to use the NuGet.CommandLine 2.8.5 package which can be found on nuget.org:

  1. First download the package by using the command Install-Package NuGet.CommandLine -Version 2.8.5 in the Package Manager Console.
  2. Then get the executable (nuget.exe) from the package's installation folder and use it to replace the NuGet 2.8.6 executable that you are currently using (i.e. in the .nuget\ folder).
  3. You may want to also check in the new executable into source control.


回答2:

In case you use TeamCity there's a way to fix this issue without changing the source code.

Go to TeamCity → Administration → Integrations → NuGet and use button "Fetch NuGet" to get 2.8.5 or 3.3.0.

Make it default if you want to use it for all projects or setup NuGet restore step to use this specific version.