Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TeamCity not restoring NuGet packages from particular package source

I have recently added a bunch of Sitecore NuGet packages to my solution from their new NuGet server: https://sitecore.myget.org/F/sc-packages/api/v3/index.json

But TeamCity doesn't seem to be able to download these:

[12:45:16][restore] Unable to find version '8.1.160302' of package 'Sitecore.ContentSearch.Linq.NoReferences'.
[12:45:16][restore] Unable to find version '8.1.160302' of package 'Sitecore.ContentSearch.NoReferences'.
[12:45:16][restore] Unable to find version '8.1.160302' of package 'Sitecore.Kernel'.
[12:45:16][restore] Unable to find version '8.1.160302' of package 'Sitecore.Kernel.NoReferences'.

I have amended the list of packages sources in my 'NuGet Installer' build step so that the Sitecore source is the only one, but yet it still can't restore these .dlls. (As a side note: I would have expected other packages to now fail because their source has been removed, but there is no error for those?)

Looking at the logs, I can see the command being fired, which looks correct:

C:\TeamCity\buildAgent\tools\NuGet.CommandLine.2.8.6\tools\NuGet.exe restore C:\TeamCity\buildAgent\work\52ce411043f6b04c\MySolution.sln -Source https://sitecore.myget.org/F/sc-packages/api/v3/index.json
like image 318
David Masters Avatar asked Nov 01 '16 14:11

David Masters


People also ask

Is it possible to run NuGet packages in TeamCity?

This works really well in Visual Studio, but when you select the Visual Studio build runner in TeamCity it does not go ahead and restore all the NuGet packages for you in the same way, so you get a compilation error. Instead, you have to explicitly create a separate step to run before the Visual Studio build step.

What is package restore in TeamCity?

The concept is simple: instead of committing packages that we depend on to source control, we only commit the list of dependencies we need and download the assemblies during build. In TeamCity, package restore is supported in various ways. We can use the NuGet.targets file (NuGet v2.6 and earlier) or run nuget restore from the command line (v2.7).

How do I restore NuGet packages in Visual Studio?

(In Visual Studio, the references appear in Solution Explorer under the Dependencies \ NuGet or the References node.) To follow the required steps to restore packages, see Restore packages.

Why is my NuGet package missing from my project?

This project references NuGet package (s) that are missing on this computer. Use NuGet Package Restore to download them. The missing file is {name}. This error occurs when you attempt to build a project that contains references to one or more NuGet packages, but those packages are not presently installed on the computer or in the project.


1 Answers

You've referenced a Nuget v3 feed but it looks like your TeamCity Nuget Installer step is set to use Nuget.exe v2.8.6. Update the setting to use v3+:

Nuget Settings

I would recommend you do not specify the Package sources in TeamCity, and instead use a Nuget.config file next to you .sln file. This also means that each developer does not need to individually add the feed sources in Visual Studio, as well as allowing the feed list to be source controlled. TeamCity will also use this list for the package sources automatically.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="Sitecore NuGet Feed" value="https://sitecore.myget.org/F/sc-packages/api/v3/index.json" />
    <add key="Custom Server" value="http://my-custom-server.org/api/v3/" />
  </packageSources>
</configuration>

You can find more details in this blog post about The right way to restore NuGet packages.

like image 153
jammykam Avatar answered Sep 22 '22 16:09

jammykam