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.
Then my project needs to be in a repository in VSTS
With that, I’m ready to configure the CI/CD build
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
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
VSTS will create a default build definition like this:
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:
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
Without closing the dialog, click add on the Nuget Publisher
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.
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.
The Manage link opens a new page, the “Settings/Services” page. Click on the green New Service Endpoint and choose generic
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.
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.
At this point the Build definition is ready. It must look like this
Click on save and provide a distinctive name for it
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.
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
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
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
Then add the server. In my case it looks like this
And with that I can pick my just created package