NuGet Package Restore with TeamCity

Maarten Balliauw

When working with NuGet we can make use of package restore. The concept is simple: instead of committing packages that we depend on to source control, we only commit the list of dependencies we need and download the assemblies during build.

In TeamCity, package restore is supported in various ways. We can use the NuGet.targets file (NuGet v2.6 and earlier) or run nuget restore from the command line (v2.7). TeamCity has a build runner which makes setting up package restore a breeze: the NuGet Installer.

NuGet Installer

The NuGet Installer build runner will make sure all package dependencies are satisfied during build. It provides several options:

We can specify the package sources that will be used to satisfy dependencies. By default, restoring will be done using but we can also make use of a private NuGet feed hosted on MyGet, ProGet or our own NuGet Gallery installation. When the current build depends on NuGet packages created by another build, we can also make use of the TeamCity NuGet feed (if enabled), for which the feed URLs are available from the %teamcity.nuget.feed.server% and %teamcity.nuget.feed.auth.server% parameters.

Other available options are disabling the local NuGet cache, forcing a fresh download of packages during every build. We can also enable auto-updating of NuGet packages if needed.

Which packages are we using?

The NuGet Installer runner also adds an additional tab on the build results page, showing the list of all packages used.

Package restore and feed authentication

When consuming NuGet packages from an authenticated feed during a build, the last thing you want to do is add credentials for connecting to that authenticated feed to source control. TeamCity has a much more elegant solution for this: the NuGet Feed Credentials Build Feature. We can add it to any build configuration, one for every feed that requires authentication.

TeamCity package restore from authenticated feed

Happy building!


Comments below can no longer be edited.

15 Responses to NuGet Package Restore with TeamCity

  1. Michael says:

    September 26, 2013

    Hello Maarten!

    Since TeamCity already logs the nuget package used and provides a nuget server as well: Does consuming a nuget package produced as a TeamCity artifact also create a keep-alive dependency between the builds so the nuget package does not get cleaned up by TeamCity as long as there are exisiting downstream builds depending on it? I’m specifically looking at the idea that you do not need to create a dependency on a specific version up-front, but simply by having your source-controlled project reference a specific TeamCity-published nuget package in a specific version.

    Best regards, Michael

    • Maarten Balliauw says:

      September 26, 2013

      Let me check with the team. I will get back to you!

      • Michael says:

        September 27, 2013

        Great, thanks!

    • Eugene Petrenko says:

      September 27, 2013

      This should be an amazing feature in TeamCity once we implement it. Unfortunately, it’s not implemented yet.
      Once you use authenticated TeamCity’s NuGet feed you may notice all downloaded packages are tracked by TeamCity as downloaded artifacts. The thing is we do not enforce NuGet to re-download all dependencies at once

      The feature could also be expanded to make TeamCity’s feed be aware of build snapshot dependencies making packages fetch/update more predictable within build chains.

      Please vote for or create your own issue to cover your exact case

      • Michael says:

        September 30, 2013

        Hi Eugene!

        Thanks for the information. Since my idea isn’t exactly a snapshot-dependency as it is implemented today, I’ve created a releated feature:

        Best regards, Michael

  2. JetBrains .NET Tools Blog » ReSharper SDK Now Available on NuGet says:

    November 7, 2013

    […] Studio, you can use the nuget restore from the command line, or as part of your CI build process. TeamCity provides a NuGet installer build step to make this […]

  3. James says:

    November 22, 2013

    The word “downloaded” is misspelled as “downlaoded” on the Used Packages tab.

  4. jgauffin says:

    January 27, 2014

    How do I get TeamCity to use the versions specified in the project packages.config? My build fails every time TeamCity downloads a newer version.

    • Maarten Balliauw says:

      January 28, 2014

      Can you check the NuGet Installer step configuration? There is an option there which allows you to enable/disable automatic updating.

      • jgauffin says:

        January 28, 2014

        Ok. I’ve disabled that now.

        So what happens if I update packages in my solution and then commits it? Will teamcity do an update then? i.e. to keep in sync with my packages.config?

        • Maarten Balliauw says:

          January 28, 2014

          It will simply follow packages.config. No updating unless packages.config says otherwise.

          • jgauffin says:

            January 29, 2014

            gr8. thanks.

  5. MyGet Blog | Migrate away from MSBuild-based NuGet package restore says:

    March 24, 2014

    […] TeamCity (how-to) […]

  6. Erik says:

    February 12, 2015

    I dont expect you to read this seeing as the post is really old, but as of teamcity v 9.0.1 (build 32116) this runner is impossible to use in a template where the solution file name is a parameter as the “solution file path” setting is hardcoded to check if the entered text ends with .sln

    • Pavel Sher says:

      February 13, 2015

      Could you please submit a bug report in our tracker?


Subscribe for updates