NuGet and TFS 2010 Automated Build

by Jason Williams5. July 2012 16:28

If you don't use NuGet for your Visual Studio projects, you should. Go download it, now.

If you do use NuGet and you want to automate your builds with TFS 2010, it's super easy to enable it:

  1. In Solution Explorer, right-click on the solution
  2. From the context menu, choose "Enable NuGet Package Restore"

One hickup you might encounter is that when your automated build tries to build the solution, you may get the following error:

C:\Builds\1\MyProject\Main Release\Sources\MyProject\ProjectName\.nuget\nuget.targets (76): Package restore is disabled by default. To give consent, open the Visual Studio Options dialog, click on Package Manager node and check 'Allow NuGet to download missing packages during build.' You can also give consent by setting the environment variable 'EnableNuGetPackageRestore' to 'true'.

The newer versions of NuGet requires explicit permission to restore packages. Usually, on your development machine, you could enable this through Visual Studio's options (per the instructions in the error message). However, on a build server, you need to add the environment variable. To do this, log into the build server and do the following:

  1. Click Start and right-click on "Computer"
  2. Choose "Properties" from the context menu
  3. Choose "Advanced System Settings" from the System window.
  4. Choose the "Advanced" tab in the System Properties window and click the "Environment Variables" button.
  5. In the System Variables section, click the "New..." button.
  6. Enter "EnableNuGetPackageRestore" for the "Variable name" field
  7. Enter "true" for the "Variable value" field and click the OK button.
  8. Lastly, restart the TFS build service and retry your build

After all of that, your build should now be able to download the NuGet packages it needs.

Happy coding!

Tags: , ,

Development | TFS | NuGet

Comments (5) -

Dave Baxter
Dave BaxterUnited States
7/12/2012 8:15:50 PM #

Just ran into this today.  Thanks for the post!

Konstantin Tarkus
Konstantin TarkusRussia
9/7/2012 10:53:37 AM #

Thanks, problem fixed

Derrick Weaver
Derrick WeaverUnited States
9/21/2012 10:05:17 AM #

I've gotten this far, but my build server keeps barking that it cannot connect to the remote server. Since servers usually do not have access to the internet here, we've given it access to the site via port 443. Are we missing something else? Do we need to give it port 80 as well? Do we have to install VS 2010 on the server (prefer not to)?


adminUnited States
9/21/2012 10:18:18 AM #


I don't like to install VS on the build server, either. In my experience, you don't need to do that to get Nuget working. However, the lack of internet connectivity could be an issue. As far as I know, https is the only protocol nuget uses, but you may want to open 80 just in case.
Also, make sure your outgoing firewall rules whitelist the entire * domain. If you do it by IP address, that may not be enough.
If you get this figured out, though please post again!

Derrick Weaver
Derrick WeaverUnited States
10/30/2012 9:33:02 AM #


It seems that some packages at are simply not there. Instead, nuget seems to "redirect" the feed (something I found with WireShark). Since our firewall is strictly IP-based, once the feed was being redirected to another IP, the connection would fail. And the more IP addresses I go to our Networking guys with, the more hesitant they are to help.

We already have an internal nuget server, so the alternate may be to download the known packages to that server instead.

If anyone else has any insight to this issue, I would greatly appreciate it.


Comments are closed


Jason Williams is a .NET developer in Lincoln, Nebraska.

The name "Centrolutions" came out of a long search for a domain name. The goal was to create a name that conveyed an ideology of writing software centered (Centr--) on a solution (--olutions) for a particular problem. In other words, it was the only name in a long list that wasn't already registered on the internet.

If you're looking for the products I have for sale, you should go here.