Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add the custom nuget feed to TeamCity build?

I have created a Nuget Server using Teamcity (running on a virtual machine in internet) and created the build that publishes a package into it.

I also have another project that needs to use that package. This project is built on teamcity as well. On my local Visual Studio I added the nuget feed uri, installed the package and everything works fine. But when I try to build it on teamcity it says that "Package not found".

So my question is : "How to add the custom nuget feed to TeamCity build?"

like image 704
Eugene Avatar asked Jan 27 '13 14:01

Eugene


People also ask

How do I publish a NuGet package to TeamCity?

When using TeamCity as a NuGet server, there are three ways to publish packages to the feed: as build artifacts of the NuGet Pack build step using the Publish created packages to build artifacts checkbox - in this case you do not need the NuGet Publish build step. via the NuGet Publish build step.

How do I add NuGet feed to Visual Studio?

In visual studio, select Preferences from the menu bar. Select NuGet, and then select Sources. Select Add, and then enter your feed's name, the source URL, a userName (any string), and your personal access token. Select OK.

What is a NuGet feed?

Cloudsmith provides public & private feeds for NuGet. NuGet is an open-source package manager designed for the Microsoft development technologies. The NuGet repository support at Cloudsmith is compatible with Chocolatey, so if you're looking to manage packages on Windows, that's our recommended approach.


2 Answers

The NuGet package sources are configured through Visual Studio, but they're stored in a per-user configuration file, found at c:\Users\$USER\AppData\Roaming\NuGet\NuGet.config. The entry for the TeamCity package source needs to be added to the config file of the build agent user that's running your builds.

  1. On your local machine, open the Nuget.config file for your user
  2. Copy the entry for the TeamCity package source to the clipboard
  3. On the build agent, open the NuGet.config file for the user that's executing your TeamCity builds
  4. Paste in the TeamCity package source entry. Save & quit.
  5. Run the build again. It should now be able to find the package.

EDIT: ladenedge documents a good solution that didn't exist when I originally answered this question. The solution is especially useful if you don't have admin access to the build agent or want to configure package sources on a per-project basis.

like image 171
John Hoerr Avatar answered Oct 02 '22 07:10

John Hoerr


NuGet can now read sources from the NuGet.targets file stored with the source itself as explained in the answer to a duplicate question.

<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="https://my-nuget-source/nuget/" /> </ItemGroup> 
like image 21
ladenedge Avatar answered Oct 02 '22 06:10

ladenedge