Nuget Restore via build server "unable to find version"

53,933

Solution 1

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.

Solution 2

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

Solution 3

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
Share:
53,933

Related videos on Youtube

Chris Kooken
Author by

Chris Kooken

Currently the CTO for DataFinch Technologies

Updated on July 09, 2022

Comments

  • Chris Kooken
    Chris Kooken almost 2 years

    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

  • timmkrause
    timmkrause almost 8 years
    Works for me again when I switch from v2 to v3. Thank you for the hint.
  • xmedeko
    xmedeko almost 8 years
    Or upgrade the nuget.exe, it will use the new URL by default.
  • Phil
    Phil over 7 years
    I was having trouble using a new private NuGet feed with an old version of NuGet.exe. To fix that, open a command prompt, cd to your .nuget folder, and run .\NuGet.exe update -self.
  • Scott Weldon
    Scott Weldon over 7 years
    I ran into the same issue after installing NuGet on Debian (NuGet Version: 2.8.1.0), and switching to the v2 API fixed it for me.
  • tjans
    tjans over 7 years
    I had the same problem but I had the "Packages Sources" field blank because it said "leave blank to use NuGet.org." This worked for a long time, but I tried queuing up a build recently and it was showing me the same behavior as Chris Kooken was seeing. Once I added the source nuget.org/api/v2 into the field, it started working. I'm not sure what changed to cause this, but this answer certainly helped me.
  • Brandon Griffin
    Brandon Griffin over 7 years
    This got me in the right direction. The url I needed for my local nuget server was in index.json.
  • MikeOnline
    MikeOnline over 2 years
    Visual Studio 2019 Professional does not come with nuget.exe. Instead, it comes with a PowerShell module for NuGet. A stand-alone nuget.exe can be downloaded from docs.microsoft.com/en-us/nuget/install-nuget-client-tools, but changing Visual Studio's NuGet configuration to search the v2 NuGet repository resolved my issue (see other answers).
  • Rod
    Rod over 2 years
    I did something similar to what you described, but instead of creating a system variable I put the current NuGet.exe (5.11.0) into a folder available to the build agent on the TFS 2015 build server. Then I put the fully qualified path to NuGet.exe into the build def. That fixed most of my NuGet problems, but not for 3 packages Newtonsoft.Json, Antlr and WebGrease.