Chris Kooken
Chris Kooken

Reputation: 33870

Nuget Restore via build server "unable to find version"

I have a VS solution and as part of a TeamCity Build, we restore packages from both a private NuGet feed (myget) and the public feed (nuget.org). Most packages restore fine, but it hangs on the ones below for WebApi and Mono.Security. This is all working locally in Visual Studio.

[restore] NuGet command: C:\TeamCity\buildAgent\plugins\nuget-agent\bin\JetBrains.TeamCity.NuGetRunner.exe C:\TeamCity\buildAgent\tools\NuGet.CommandLine.DEFAULT.nupkg\tools\NuGet.exe restore C:\TeamCity\buildAgent\work\953bd084b49f7d88\DataFinch.Web.sln -Source https://www.myget.org/F/datafinch/auth/<hidden>/api/v2 -Source https://api.nuget.org/v3/index.json
[11:41:35][restore] Starting: C:\TeamCity\buildAgent\temp\agentTmp\custom_script473789219385667038.cmd
[11:41:35][restore] in directory: C:\TeamCity\buildAgent\work\953bd084b49f7d88
[11:41:35][restore] JetBrains TeamCity NuGet Runner 8.0.37059.9
[11:41:35][restore] Registered additional extensions from paths: C:\TeamCity\buildAgent\plugins\nuget-agent\bin\plugins-2.8
[11:41:35][restore] Starting NuGet.exe 2.8.50926.602 from C:\TeamCity\buildAgent\tools\NuGet.CommandLine.DEFAULT.nupkg\tools\NuGet.exe
[11:41:43][restore] Unable to find version '5.2.3' of package 'Microsoft.AspNet.WebApi.Client'.
[11:41:43][restore] Unable to find version '5.2.3' of package 'Microsoft.AspNet.WebApi.Core'.
[11:41:43][restore] Unable to find version '3.2.3.0' of package 'Mono.Security'.
[11:41:43][restore] Unable to find version '6.0.4' of package 'Newtonsoft.Json'.
[11:41:43][restore] Process exited with code 1

Teamcity config: enter image description here

Upvotes: 45

Views: 63932

Answers (6)

fusion27
fusion27

Reputation: 2636

Using an old version of Visual Studio's Nuget

  • Visual Studio has C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\Nuget.exe. Jenkins was using that to nuget restore
  • Updated Nuget in program files,
    C:\Program Files (x86)\NuGet> ./nuget.exe update -self
    
  • Pointed Jenkins at that new Nuget path and 🔥cooking with gas🔥
    SET PATH=%PATH%;C:\Program Files (x86)\NuGet
    nuget restore SolutionName.sln
    

Upvotes: 0

Post Impatica
Post Impatica

Reputation: 16393

According to THIS current document as of this writing from MS, the proper url is: https://api.nuget.org/v3/index.json

So I went about to fix the issue because I assumed it had nothing to do with the URL. I did 2 things, not sure which it was that resolved the issue but I'll post both here in case it helps someone.

  • Within TFS2018 and within my build step for the installation of Nuget I specified version 4.9.3 (the reason I chose 4.9.3 because I noticed by looking at detailed log of VS that during my build it was using this version) and chose to always download the latest version.

  • Second thing I did was I removed a Nuget.Config file from my project that was left over from something I was testing. Then I re-commited my changes to TFS

After I did both of the above steps the rest of my build started working.

Upvotes: 0

Marcel Beeker
Marcel Beeker

Reputation: 171

The reason why the build failed, was an old version of nuget.exe. I finally solved this problem by downloading the latest version and put this executable in the Program Files x86 folder. Then I created a new system variabele to point to this executable. After that I add a NuGetInstaller package in my TFS Build Definition to let me configure TFS using this new NuGet.exe. This link helped me to let TFS use this new NuGet version

Upvotes: 3

kayleeFrye_onDeck
kayleeFrye_onDeck

Reputation: 6958

I ran into this problem with one of our build slaves leveraging TFS and Visual Studio.

The way I fixed it was, I opened the solution that wasn't compiling in Visual Studio, right-clicked on the SLN and selected "Enable Restore NuGet Packages"

That prompts a dialog box that you have to accept. After you've done that, you might be good to go. Right-click on the SLN again and run "Restore NuGet Packages", and if that operation succeeds, you're golden.

There's probably some setting you can adjust programmatically when setting up your slave environments, but that's one direct way to fix this kind of problem.

Upvotes: 0

Jeremy Thompson
Jeremy Thompson

Reputation: 65554

I followed this: https://blogs.msdn.microsoft.com/tfssetup/2017/04/18/tfs-2017-update-1-nuget-restore-task-always-fails-trying-to-find-packages-even-though-they-exist-on-the-feed/

I had tried 3.3 and got this error:

Restoring NuGet package Microsoft.AspNet.WebPages.3.2.3. WARNING: Unable to find version '3.5.0.2' of package 'Antlr'.

I downloaded the latest NuGet 4.3.0.4406 and set the Custom path to NuGet and that failed as well.

Surprisingly when I switched to 3.5 it worked.

enter image description here

If you are really stuck, run the command in a Command Line Prompt and it will work:

C:\Program Files (x86)\NuGet\nuget.exe restore -NonInteractive E:\agentXYZPool\_work\1\s\xyz.sln

Upvotes: 1

rarrarrarrr
rarrarrarrr

Reputation: 1149

Try using https://www.nuget.org/api/v2instead of https://api.nuget.org/v3/index.json per the nuget docs: https://docs.nuget.org/consume/Command-Line-Reference.

Upvotes: 46

Related Questions