dreadwail
dreadwail

Reputation: 15419

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

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?

Upvotes: 40

Views: 33647

Answers (5)

Fabian Hänggi
Fabian Hänggi

Reputation: 1

in tfs build 2017 when you use the NuGet Restore task version 1.* you can select the NuGet.Config file to use during the build. See image below NuGet Restore Task

Upvotes: 0

Jeff Shepler
Jeff Shepler

Reputation: 2115

Another option is to add sources to a machine-wide (not user-specific) nuget config on the build server.

https://stackoverflow.com/a/27569020/374837

Upvotes: 3

Velimir
Velimir

Reputation: 762

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

Upvotes: 31

Xavier Decoster
Xavier Decoster

Reputation: 14810

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>

Upvotes: 19

dreadwail
dreadwail

Reputation: 15419

According to pranavkm, one of the NuGet devs, at the time of this writing NuGet Package Restore will not use the NuGet.config in the hidden '.nuget' folder for sources. It's only used at the moment for a solution specific setting (to ignore source control bindings). He says it is on the radar for the NuGet team to leverage all aspects of NuGet.config but that it keeps getting bumped in priority.

Upvotes: 6

Related Questions