Michael Whelan

behaviour driven blog

Restoring NuGet Packages in TeamCity

NuGet package restore used to be MSBuild-based and you would enable it by selecting Enable NuGet Package Restore in Visual Studio. Nowadays, it is recommended that you don't use this approach, but instead just set the option in Visual Studio to Allow NuGet to download missing packages. This works really well in Visual Studio, but when you select the Visual Studio build runner in TeamCity it does not go ahead and restore all the NuGet packages for you in the same way, so you get a compilation error. Instead, you have to explicitly create a separate step to run before the Visual Studio build step.

To enable NuGet Package Restore with TeamCity you need to add a build step before the Visual Studio solution build with a runner type of NuGet Installer.

TeamCity NuGet Installer

The first time you create this installer, there might not be a NuGet.exe to choose. Just select the NuGet Settings option and you are presented with the option to download the latest version. Select Fetch NuGet and you are able to select a NuGet.exe version to be downloaded for use by TeamCity.

TeamCity NuGet Installer

Once you have selected the NuGet.exe you just have to provide the path to your Visual Studio solution file, which you can do with the useful file tree (pictured):

TeamCity NuGet Installer

Find out more

I can recommend some great resources on using TeamCity for continuous integration/delivery from my fellow TestStackers:

  • Mehdi Khalili has a definitive post on doing continuous integration and delivery for GitHub with TeamCity.
  • Rob Moore and Matt Davies have a great series of posts on creating a deployment pipeline with TeamCity.
  • Jake Ginnivan has a ton of great posts on TeamCity and continuous delivery. I particularly like this one, on setting up a UI test build agent with TeamCity.

In additiona, JetBrains also has a blog post that goes into more detail about the NuGet Installer build runner.

About Michael Whelan

Michael Whelan is a Technical Lead with over 20 years’ experience in building (and testing!) applications on the Microsoft stack. He is passionate about applying agile development practices, such as BDD and continuous delivery, to agile processes. These days his primary focus is ASP.Net MVC Core and Azure. He contributes to a number of open source frameworks through TestStack.

comments powered by Disqus