Continuous Integration & Deployment of a NuGet Package with VSTS

In this post I’ll show the configuration steps to setup a CI/CD in Visual Studio Team System that from a repository build, packages and publishes a NuGet Package.

To publish a NuGet Package you will need a NuGet server. There are lots of options, and VSTS itself provides one. In my case I setup one using the free Nuget.Server (http://nugetserver.net/) and hosted it on a free tier Azure Web Site. Having that, I’m all set.

First I need the project from which I will then generate the package, so first make sure to have a Visual Studio solution that builds, and that doesn’t have any weird local references since the build will be done by the hosted build service in VSTS. Nuget dependencies are fine, since the CI can take care of that.

image

Then my project needs to be in a repository in VSTS

image

With that, I’m ready to configure the CI/CD build

image

Leave the defaults in the “Select a template”, be aware however that this screen can change at any time so check the options and selection in your case

image

In the “Create new build definition” screen pick the right repository, branch, and check the Continuous integration option if that is really what you want. If you leave it blank you will need to manually start each build, or schedule it in some other way

image

VSTS will create a default build definition like this:

image

Leave only the first two steps, delete the rest.

To delete a step, first click over it and then on the red arrow to the right next to it:

image

Click on the green Add build step on top of the steps list and in the Task Catalog dialog select Package and look for the Nuget and click Add

image

Without closing the dialog, click add on the Nuget Publisher

image

Then click on Close to dismiss the Task Catalog dialog. Click on the NuGet Publisher step to reveal the configuration. If you are using the Nuget server provided by VSTS then choose “Internal Nuget Feed” and copy/paste the Url provided by the extension.

image

In my case since I have a external server I left the Feed type as External and clicked on the Manage link to the right of the Url. This is needed only the first time. After the server is setup it will be available in the dropdown control for NuGet Server Endpoint.

image

The Manage link opens a new page, the “Settings/Services” page. Click on the green New Service Endpoint and choose generic

image

In the Add new Generic Connection dialog use a friendly name for Connection Name and fill out the Url and Username and Password if needed. In my case with the Nuget.Server I have I passkey so I typed it there.

image

After clicking Ok close the Settings page to go back to the Build page, Click on the refresh icon next to the Url to have the server available and select the server.

image

At this point the Build definition is ready. It must look like this

image

Click on save and provide a distinctive name for it

image

And that’s it!, if you selected the continuous integration the Build will run automatically every time you check in changes in the repo/branch selected at the beginning. To run the build manually click on “Queue build…” and leave the default options. The BuildConfiguration option is particularly important since without it, or misconfigured the build will fail.

image

Moments later a build agent will pick the job and you will be able to see the output of the build tasks in real time

image

Then the build will finish. If something fails, it will be red, and the logs will help to find the issue, probably some issue with dependencies in the Visual Studio Solution

image

To then consume my package, if I haven’t already added my Nuget server I need to do it in the Options screen in Visual Studio. One quick way to get to the right place is to open the Nuget Package Manager and click on the Gear

 

image

Then add the server. In my case it looks like this

image

And with that I can pick my just created package

image

Advertisements

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

%d bloggers like this: