40

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?

dreadwail
  • 15,098
  • 21
  • 65
  • 96

5 Answers5

31

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

Velimir
  • 684
  • 7
  • 7
  • That's an interesting definition of "without any special configuration". In fact, the implementation of Restore documented there is via a custom build process - nothing to do with the Build Process Template. Not that any of this answers the OP's question. – bornfromanegg Jul 10 '14 at 14:26
  • 1
    @user1158174 if you look at the very beginning of the article on that page, it states: `For Team Foundation Build 2013 on-premises and Visual Studio Online (formerly Team Foundation Service), the default Build Process Templates already implement the NuGet Package Restore workflow without any special configuration. The following information only applies to Team Foundation Build 2012 and earlier, or to Build Process Templates that have been customized and had the NuGet Restore functionality removed.`, so yes, TFS 2013 already does it 100% automatically (we actually use that in our company). – julealgon Jan 23 '15 at 18:08
19

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>
Matt Ward
  • 47,057
  • 5
  • 93
  • 94
Xavier Decoster
  • 14,580
  • 5
  • 35
  • 46
  • 4
    That didn't answer the question at all. I already pointed out that you can use NuGet.targets to specify the sources. The question was about NuGet.config and whether it would be used. – dreadwail May 17 '12 at 20:33
6

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.

dreadwail
  • 15,098
  • 21
  • 65
  • 96
  • 3
    FYI, update: Hierarchical NuGet.configs are supported as of v2.1. See http://docs.nuget.org/docs/release-notes/nuget-2.1 – Xavier Decoster Feb 14 '13 at 12:35
  • 1
    For future internet searchers out there, the command line version of "nuget.exe" is -Source "https://www.nuget.org/api/v2/;http://myother source/myrepository/" – granadaCoder Sep 04 '13 at 16:57
3

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

Community
  • 1
  • 1
Jeff Shepler
  • 2,007
  • 2
  • 22
  • 22
0

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