28

I have a package on my TeamCity NuGet feed, built by TeamCity, but a dependent TC project cannot see it during package restore.

[14:05:02][Exec] E:\TeamCity-BuildAgent\work\62023563850993a7\Web.nuget\nuget.targets(88, 9): Unable to find version '1.0.17.0' of package 'MarkLogicManager40'.

[14:05:02][Exec] E:\TeamCity-BuildAgent\work\62023563850993a7\Web.nuget\nuget.targets(88, 9): error MSB3073: The command ""E:\TeamCity-BuildAgent\work\62023563850993a7\Web.nuget\nuget.exe" install "E:\TeamCity-BuildAgent\work\62023563850993a7\ProductMvc\packages.config" -source "" -RequireConsent -solutionDir "E:\TeamCity-BuildAgent\work\62023563850993a7\Web\ "" exited with code 1.

Note that the source parameter in the NuGet command line is empty. Could this be the cause?

Community
  • 1
  • 1
Luke Puplett
  • 42,091
  • 47
  • 181
  • 266
  • The method for adding a custom NuGet feed to TeamCity [has previously been addressed](http://stackoverflow.com/questions/14548324/how-to-add-the-custom-nuget-feed-to-teamcity-build) – John Hoerr Jun 17 '13 at 16:39
  • Now I know the answer, I know the question. – Luke Puplett Jun 17 '13 at 17:32

2 Answers2

43

As of today, NuGet.targets has the following way to specify custom feed(s):

<ItemGroup Condition=" '$(PackageSources)' == '' ">
    <!-- Package sources used to restore packages. By default, registered sources under %APPDATA%\NuGet\NuGet.Config will be used -->
    <!-- The official NuGet package source (https://nuget.org/api/v2/) will be excluded if package sources are specified and it does not appear in the list -->

    <PackageSource Include="https://nuget.org/api/v2/" />
    <PackageSource Include="\\MyShare" />
    <PackageSource Include="http://MyServer/" />
</ItemGroup>

Another option is to put NuGet.config next to the solution file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
    <add key="MyShare" value="\\MyShare" />
    <add key="MyServer" value="http://MyServer" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)"  />
  </activePackageSource>
</configuration>
abatishchev
  • 98,240
  • 88
  • 296
  • 433
  • Does the nuget.exe (command line) utilize the NuGet.targets information? I'm running this .............. C:\MyProgFiles\NuGet\NuGet.exe install ".\.nuget\packages.config" -ConfigFile ".\.nuget\nuget.config" -NoCache ............ and it finds the package in the public repository, but not my private repository. The file "\.nuget\NuGet.targets" exists and has the additional PackageSource (as seen in your post). But I keep getting "Unable to find version" errors (it does exist) on the package in the private repository. Thanks for any help. – granadaCoder Sep 04 '13 at 13:27
  • 1
    @granadaCoder: use -Source argument. – abatishchev Sep 04 '13 at 17:16
  • 3
    Thanks. I didn't know you could provide multiple semi-colon delimited Source(s). For future readers ::: -Source "https://www.nuget.org/api/v2/;http://myprivateserver/nuget/" – granadaCoder Sep 04 '13 at 18:15
  • 1
    Does this work for Automatic Package Restore or only with the MSBuild-Integrated package restore? – Dave New May 29 '14 at 08:22
  • 1
    I don't think feed source is related to auto-restore. So should work for both. – abatishchev May 29 '14 at 14:20
  • Your first example uses a `$(PackageSources)` property in the condition but then proceeds to initialize the `PackageSource` item _list_. Which one works, and when? – Andrew Arnott Nov 15 '14 at 13:57
  • 3
    In the NuGet Installer step, there is now a "Package Sources" field that you can fill in to have team city use a custom feed. – archangel76 Dec 19 '14 at 22:30
9

Apparently NuGet custom feeds are set not via anything in the solution or project files, or nuget.config in the solution, but in the nuget.config in the developer's profile.

Over on TeamCity, there's no check by the agent of this config file, or writing to it, to ensure it contains the feed for the TeamCity server itself.

So package restore on TC using a custom TC feed won't 'just work'. You have to waste hundreds of pounds of client's money chasing your tail to discover all this and then set/copy your nuget.config from your profile into the profile of the user account running the build agent.

Horrible.

Luke Puplett
  • 42,091
  • 47
  • 181
  • 266
  • 7
    To get it working with TeamCity using the checked in source code you can add the custom package sources to the NuGet.targets file. Another way is to use the custom NuGet Installer runner as a build step before you compile the solution. Not sure why package sources in the the NuGet.config file are ignored presumably because the custom .targets file does not import this or read it. – Matt Ward Jun 17 '13 at 16:46
  • I switched the answer to reflect the better method. – Luke Puplett Jul 29 '13 at 20:07