3
votes

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>
2
The new Automatic package restore, which does not use MSBuild, is built into Visual Studio. Presumably TFS is not going to use Visual Studio to build the solution. I would look to see if you can setup a pre-build step in TFS which runs "nuget restore YourSolution.sln". Assuming you do not want to use the MSBuild based package restore.Matt Ward
You're right - that was the problem. The "pre-build" step is simply part of the custom build that needs to be created. If there's a way of setting up a pre-build step as part of a build definition, that would also be useful, but can't see one.bornfromanegg
I'm having a problem with the stuff at the link [link]docs.nuget.org/consume/package-restore/team-build. It restores all the packages, but doesn't even try to build the solution. Further the output of msbuild shows it ran "C:\Builds\1\Services\MyProject\src\tools\NuGet\NuGet.exe" restore "" Why an empty string? Why not the .sln folder it found? It DID restore packages to the packages folder under src. Further, if I try to manually build the solution, now all the projects inside fail saying that the packages couldn't be found. Any idea what I'm doing wrong?Randy Magruder

2 Answers

3
votes

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.

-1
votes

depending on the version of visual studio, it should just be a matter of right clicking on the solution and selecting Enable NuGet Package restore. this will create a Nuget folder that contains, NuGet.exe, a NuGet.Targets file and NuGet.config.

you can update the targets file with a local NuGet Feed if you have one.

to test locally, delete the contents of your packages folder, and ReBuild the solution, this will download the files from NuGet and your solution should build correctly. check in the NuGet folder and files to source control, your packages should not be added to source control.

your TFS build should now be able to restore the packages

NuGet Restore

Now if this is how you are set up and it still doesn't work on TFS, log onto the build server with the build account and load the solution locally, make sure the package restore works as the build account on the build machine, you may have a firewall / proxy issue, where the build server / build account can't access the Nuget.org internet site