Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Unable to find version" during TFS Build 2015 when restoring NuGet packages

I'm having troubles with NuGet package restoring during a TFS Build 2015.

Since some packages require NuGet 3.x client, I've configured the new scriptable build to use a custom NuGet location where I've placed the executable of NuGet Command-Line 3.x beta.

Whenever I run a build, all packages can't be restored and NuGet throws the "Unable to find version..." error:

Unable to find version '1.1.10' of package 'Microsoft.Bcl'.
Unable to find version '4.0.10' of package 'System.Threading'.
Unable to find version '1.1.37' of package 'System.Collections.Immutable'.
Unable to find version '1.0.0' of package 'Owin'.
Unable to find version '4.1.0' of package 'NLog'.
Unable to find version '7.0.1' of package 'Newtonsoft.Json'.
Unable to find version '2.0.1' of package 'MongoDB.Driver.Core'.
Unable to find version '2.0.1' of package 'MongoDB.Driver'.
Unable to find version '2.0.1' of package 'MongoDB.Bson'.
Unable to find version '3.0.1' of package 'Microsoft.Owin.Security.OAuth'.

...and even more packages. I believe the issue is clear.

When I build the same solution in the build machine using Visual Studio, all packages are restored sucessfully.

How do I solve this?

like image 735
Matías Fidemraizer Avatar asked Sep 07 '15 08:09

Matías Fidemraizer


People also ask

How do I restore NuGet packages in Visual Studio 2015?

Restore packages manually using Visual StudioEnable package restore by choosing Tools > Options > NuGet Package Manager. Under Package Restore options, select Allow NuGet to download missing packages. In Solution Explorer, right click the solution and select Restore NuGet Packages.

How do I find the NuGet package version?

In Visual Studio, use the Help > About Microsoft Visual Studio command and look at the version displayed next to NuGet Package Manager. Alternatively, launch the Package Manager Console (Tools > NuGet Package Manager > Package Manager Console) and enter $host to see information about NuGet including the version.

What is NuGet restore in TFS build?

With NuGet Package Restore you can install all your project's dependency without having to store them in source control. This allows for a cleaner development environment and a smaller repository size. You can restore your NuGet packages using the NuGet restore task, the NuGet CLI, or the . NET Core CLI.


3 Answers

In my case, the issue was that user-wide NuGet.config located at C:\Users\[User name]\AppData\Roaming\NuGet\NuGet.config (where [User name] is the user who's running the build agent's Windows service) was pointing to NuGet API v2 while my build is already using NuGet Command-Line 3.x.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <!-- CHANGING V2 TO V3 IN THE URI VALUE SOLVED THE ISSUE! -->
    <add key="nuget.org" value="https://www.nuget.org/api/v3/" />
  </packageSources>
</configuration> 
like image 102
Matías Fidemraizer Avatar answered Oct 03 '22 03:10

Matías Fidemraizer


In my case the Nuget.Config, was in:

C:\Windows\ServiceProfiles\NetworkService\AppData\Roaming\NuGet

So search for Nuget.Config in your C:\.

The user depends on the account that you configured the Agent

like image 33
willianleite Avatar answered Oct 03 '22 03:10

willianleite


If for some reason updating the NuGet.config in the Roaming folder is not an option or unwanted, it is also possible to add the config file to the solution root.

According to the docs:

  • Project-specific NuGet.Config files located in any folder from the solution folder up to the drive root. These allow control over settings as they apply to a project or a group of projects.
  • A solution-specific NuGet.Config file located within a .nuget folder in the solution. Settings in this file apply only to solution-wide packages and is supported only in NuGet 3.3 and earlier. It is ignored for NuGet 3.4 and later.

Config file locations and uses

like image 27
Emiel Koning Avatar answered Oct 03 '22 04:10

Emiel Koning