Features How-To's Tips & Tricks

NuGet Package Restore with TeamCity

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 NuGet.org 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!


image description