Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify NuGet sources for build server to use with NuGet Package Restore?

Tags:

nuget

tfs

I'm using NuGet Package Restore. I want to specify custom sources during a TFS build server process.

The NuGet.targets file in the hidden '.nuget' folder says that you can either specify sources repositories, or that it will fall back to the NuGet.config in %APPDATA%\NuGet\NuGet.config.

There is however a NuGet.config in the hidden '.nuget' folder as well. I assumed that if you did not specify sources repositories in NuGet.targets that it would fall back to the NuGet.config in the hidden '.nuget' folder. This doesn't seem to be the case.

Any ideas?

like image 695
dreadwail Avatar asked May 17 '12 18:05

dreadwail


People also ask

How do I run a NuGet package restore?

Enable 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.

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.

Where can I find NuGet package source?

From the Tools menu, select NuGet Package Manager | Package Manager Settings. The Options dialog box appears. In the left pane, select Package Sources.


2 Answers

With the current version of NuGet it's possible to specify custom repositories in the solution's NuGet.config file and enable package restore during a build. Having this NuGet.config file allowed us to automatically restore packages from internal repository under a TFS build without any other actions in the build definition:

<configuration>   <solution>     <add key="disableSourceControlIntegration" value="true" />   </solution>    <packageSources>     <add key="Internal" value="http://MyInternalRepository/nuget" />   </packageSources>    <packageRestore>     <add key="enabled" value="True" />   </packageRestore>  </configuration> 

Note: TFS2013's default Build Process Templates already implements NuGet Package Restore workflow without any special configuration as stated here: http://docs.nuget.org/docs/reference/package-restore-with-team-build

like image 126
Velimir Avatar answered Sep 21 '22 16:09

Velimir


If you enable package restore, you'll find a NuGet.targets MSBuild file in the $(SolutionDir)\.nuget folder.

You can set the package sources by modifying the <PackageSources>""</PackageSources> element.

Example:

<!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config --> <PackageSources>"http://packages.nuget.org/api/v2/;http://myget.org/F/myfeed/"</PackageSources> 
like image 24
Xavier Decoster Avatar answered Sep 18 '22 16:09

Xavier Decoster