Manage dependencies with NuGet and TFS

I have a lot of customers that had played with NuGet packages some time ago and found it too difficult. Wresting with spec and config files and using command line tools is not everybody’s thing. That’s why I’ve written today a small documentation how you use NuGet today together with the TFS or VSTS to manage the dependencies between you projects. I think this is useful for many teams so I decided to share it.

Enable NuGet in Visual Studio Project

To use nuget you have to use nuget.exe. Download it an place it somewhere in your %PATH%.

If you want to enable packaging for a Visual Studio project, open the the package manager console (Tools / NuGet Package Manager / Package Manager Console). Navigate to the project where your project file (csproj) is located. Execute

nuget spec

Enable NuGet in VS Project

This generates a nuspec file inside your project folder with the same name as your project. The file contains a lot variables that get populated with values from the project.

<?xml version="1.0"?>
 <package >
  <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
  <copyright>Copyright 2016</copyright>
  <tags>NuGet Demo</tags>

Make sure that all the properties are filled in your project. Description for example is empty per default. It will throw an error when you package if you don’t set the value or remove the variable.


The cool thing is: if your package has nuget packages installed, they automatically get added as a dependency.


Enable Package Creation and Publishing in Team Build

Add a “NuGet packager” step to you’re your build. Change the path/pattern to use your .csproj instead of the .nuspec file.


To publish the package you have to add a “NuGet publisher” build step. You can leave the pattern to publish all packages or specify the path to a specific – depending your project structure. The server endpoint can be anything that accepts nuget packages. This can be, a custom nuget server, a file share or TFS/VSTO. To the latter I will come in the next chapter.


The simplest thing would be to have a file share. The syntax for that would be file://server/share.


TFS / VSTS Package Management Extension

If you install TFS 2015 Update 2 you now also have access to the market place. In VSTS this is already available for some time. You can install the “Package Management” extension – this allows you to host your own feeds inside TFS/VSTS.

Note: the extension is still in preview.

To install the extension to just browse the marketplace, search for the extension and install it in your account.



After the installation is complete you have a new tab “PACKAGES*” (the star marks the feature as preview). To create a new feed and enter a name and description. Chose if you want a private feed (scope team project) or a global feed (scope account). Also choose who can add packages to the feed.


Copy the URL of the feed to your clipboard.


To publish to the feed set the feed type in the “NuGet Publisher” build step to internal and enter the URL of the feed.


To consume the feed from the client and retsore from it during the build you have to configure the package source. Just add a nuget.config to your solution folder and add the package source.

<?xml version="1.0" encoding="utf-8"?>
  <add key="" value="" />
  <add key="Internal" value="" />

In your team build just reference the nuget.config and the build will automatically restore any package from the source.



So that’s it. With a few clicks and just one command line you can create a loos coupling between your projects and manage your dependencies using nuget package. I hope this is good jump start for teams new to this. Leave me a comment or contact me on twitter if you need further help.

One thought on “Manage dependencies with NuGet and TFS

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s