Search code examples
visual-studiotfsnugetbuild-processnuget-package-restore

Nuget Automatic Restore - Specifying custom repositories for TFS Build


I am attempting to migrate to nuget's new Automatic Package Restore. Whilst it works fine on my own machine (packages are restored), builds performed as a TFS Build on the build server do not build, complaining that they cannot find the various dlls (that should have been downloaded as part of the restore).

I have created a nuget.config in my solution folder, as specified here:

http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html

I have also tried putting this nuget.config file next to the nuget.exe file in TFS, in the hope that it would be used, but to no avail.

The nuget reference here:

http://docs.nuget.org/docs/reference/nuget-config-file

states that the nuget.config in my solution folder should be picked up. But it appears that it isn't.

I'm at the end of my tether. According to nuget, the Package Restore feature is designed specifically so that packages don't need to be checked in. However, there's scant information about how to get TFS to actually restore the packages, and what I've found does not work.

Any help would be gratefully received.

My nuget.config looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
    <add key="ads" value="<address to local repository>" />
  </packageSources>
</configuration>

Solution

  • As it so often turns out, the answer is the answer to a question I didn't actually ask:

    "How does TFS even know how to call nuget?"

    After sitting and thinking about this for a while (and as @Matt Ward correctly points out) it occurred to me that the TFS Build has no way of knowing nuget is even involved, since the new "Automatic" package restore removes the need for it to be part of the build itself.

    This question has actually been asked here:

    How does TFS know about nuget?

    Although the accepted answer is NOT actually the correct one. Scroll down to probackpacker's answer, which is essentially that:

    "If you are using automatic package restore, you must have a build process that calls it before building your solution"

    This is actually well documented at nuget:

    http://docs.nuget.org/docs/reference/package-restore-with-team-build

    However, I had disregarded it since a) the entire point of Automatic Package Restore is to move away from an MSBuild based process (although I do now understand why this is different), and b) it seemed more complicated than I needed. It's not. That said, a clarifying statement such as "If you are using Automatic Package Restore with TFS Team Build, you MUST create a an MSBuild project in order to call Package Restore" would have been helpful. It's obvious once you understand what's happening - confusing when you don't. But we live and learn.