NuGet and TFS 2010 Automated Build


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:

[more]

  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!