Continuous delivery of Nuget packages to Package Management in TFS15 RC1Aug 14, 2016 | Utkarsh Shigihalli TFS15 DevOps TeamFoundationServer
TFS 15 RC1 got released a couple of days ago and one of the most awaited features from on-prem customers was Package Management.
In this post, we will see how we can publish our common code as NuGet packages so that it can be shared across the organization. Also, we will see how we can keep these packages up to date by publishing them to our TFS15 package management server as part of our continuous delivery process.
Install Package Management extension
To use the TFS15 Package Management on on-prem, you first need to install the Package Management extension. The package management extension now comes as part of TFS15 RC1 installation. To install, you first need to go to your local marketplace.
On your on-prem server home (
http://localhost:8080/tfs for example) click on marketplace icon and then click
Browse TFS extensions
You will be taken to your local extension marketplace.
Package Management extension and install it on to your desired TFS collection.
Create a package feed in Package hub
A package feed is a container of your packages. Package clients similar to
NuGet Package Managerof Visual Studio will be able to subscribe to this feed and receive packages.
Once you install the extension, you should see
Package Feeds in your navigation bar under
Build/Release menu. Click
You will be navigated to
Package Feeds screen.
New Feed. This opens a new dialog. Provide the feed details.
Once you click OK, a new NuGet feed will be created.
Note down the feed URL from the feed details page on the right side. We will use it later in the post to publish our packages to this feed. Also, If you want to use your own instance of
nuget.exe you can download it from here.
Manage feed Security
You can right click on the feed, click
Edit - to manage its security, such as who can contribute packages, who can consume the packages etc.
Build and publish NuGet packages solution
Now we are in a position to build our solution and publish the nuget packages. For this post, I have two of my commonly used libraries which I would like to publish as NuGet packages.
My code structure is as below.
Now to build the solution, I have created a simple build definition with following steps.
Most of the steps are self-explanatory. However, I would like to briefly describe the following important steps.
- NuGet Packager : I use this task to package my code in to nupkg files. This task scans either csproj/nuspec file and packages in to nupkg file.
- In the next task I publish the generated nupkg file as artifacts of this build. This task also copies packages in to
- NuGet Publisher : Finally, I use this task to find all the packages in the
$(build.artifactstagingdirectory)and publish this to our feed.
Let’s see packaging and publishing task in detail.
As the name indicates, the first task is is used to pack the code as Nuget package. The details of the task configuration is as below.
As the name indicates, this task is is used to publish the code to our Nuget feed. The details of the task configuration is as below.
Notice that for publishing to local package feed you need to select feed type as
Internal NuGet Feed.
The next parameter is to provide the feed URL generated during the feed creation step above. For me it was as below.
Save the build definition and Queue a new build. If everything is set right, your build should be green and you should see your packages available in the feed.
Consuming the NuGet feed
You or your team is now ready to consume these NuGet packages. The details page, when you create the feed, already gives instructions on how to add this feed as a source to your package manager client (for example Visual Studio’s NuGet Package Manager). The command, to add this feed as a source is
1 nuget.exe sources Add -Name "MyCompanyNuget" -Source http://localhost:8080/tfs/DefaultCollection/_packaging/MyCompanyNuget/nuget/v3/index.json
Execute the above command on the client machine command prompt. This should update the Nuget.config file and you will see a new NuGet source.
If you are Visual Studio user, you can also add this source by going to
Tools | Options | NuGet Package Manger | Package Sources and providing feed URL as below.
Once you have added the NuGet source, you can see the new NuGet source in the Nuget Package Manager. You can select this source specifically or select All, to find your published NuGet packages.
That’s it. You have integrated publishing your NuGet Packages to the local package feed within your TFS 15. So every time you update your package, you are publishing the latest packages to the NuGet feed, thus making sure your team always consumes latest packages.
Thanks for reading.