5

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.

Sherlock
  • 116
  • 5
  • Not sure where you got NuGet.exe from but the one in the NuGet.CommandLine NuGet package (version 2.8.6) targets .NET 4.5 so you are correct. Older versions targetted .NET 4.0 – Matt Ward Jul 28 '15 at 16:23
  • Well, that's a pretty [infamous error message](http://stackoverflow.com/a/13750130/17034). It was built wrong, it will only work on a machine with 4.5 installed. So you're pretty much stuck with the old version right now. – Hans Passant Jul 28 '15 at 16:47
  • 1
    Thanks for the responses - quite alarming that a "patch" release x.x.6 would be where they changed targeting to .NET 4.5. :( – Sherlock Jul 28 '15 at 18:45
  • Has anyone raised this as a bug with the NuGet team? This is essentially bad linking in a way that makes it incompatible with .NET 4.0... – Philip Atz Oct 20 '15 at 00:48
  • Unknown Philip, do you know where/how to check? – Sherlock Oct 20 '15 at 00:51
  • @JohnWatson Did you manage to solve this issue? – f470071 Nov 05 '15 at 21:15
  • @f470071 I uninstalled Chocolatey (actually, renamed the folder) and forced the install of 0.9.8. I hacked my own posh script together but Rob [ferventcoder] has an "official" one for this: https://chocolatey.org/install-lastposhclient.ps1 – Sherlock Nov 05 '15 at 21:22
  • @JohnWatson I do not follow you. I thought this is a nuget issue. I am not familiar with chocolatey. – f470071 Nov 05 '15 at 21:40
  • Sorry, my mistake for rushing too quickly. Disregard my last response. Other than @PhilipAtz logging the issue the only thing I've been able to do is prevent updating those build machines beyond NuGet 2.8.5 – Sherlock Nov 05 '15 at 21:44
  • @JohnWatson Well you could post how did you achieve that as an update to your answer. It might be welcomed by somebody. As for myself, I am strugling to get my nuget back to version 2.8.5. – f470071 Nov 06 '15 at 08:16
  • I'm getting the exact same symptoms in TeamCity 9.1.4 which I wasn't getting in 8.1, I think the upgrade installed this bung nuget. – Myster Dec 09 '15 at 23:15

2 Answers2

2

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.
Philip Atz
  • 886
  • 1
  • 10
  • 26
  • Thank you. I missed this one of my comments otherwise I would post. Yesterday the released nuGet 2.9 which fixes this .NET 40/45 problems. But thank you. Your tip with command line workaround would probably work. – f470071 Nov 08 '15 at 20:52
  • This is the link to NuGet Command line: https://www.myget.org/F/nuget-volatile/api/v2/package/NuGet.CommandLine/2.9.0 – f470071 Nov 09 '15 at 06:37
1

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.

NuGet setup in TeamCity

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92