Publish NuGet Package using VSTS Build Pipeline

Generating a nugget package during build is as simple as the following steps:

  1. Define the NuGet Specification
  2. Pack the NuGet Package
  3. Push the NuGet Package to your repository

Now the implementation gets a bit tricky.

Define the specification

You will need to ensure that nuget.exe is in your path. It’s as simple as creating a folder and dropping the exe in there then adding that folder to your PATH environment variable.

Then simply open the Visual Studio Developer command prompt, navigate to the folder of the project you want to create a NuGet package for and then execute the command ‘nuget spec’.

Pack the NuGet Package

In VSTS, there are two ways you can Pack a NuGet Package. Using either the ‘NuGet’ action which works for .NET Framework assemblies or ‘.NET Core’ action which works for .NET Core and .NET Standard assemblies.

It’s important that you select 2.* (preview) otherwise the ‘pack’ command is not available.

Make special note that the .NET Core icon changes when you do this.

You can use the following syntax to select:

  1. A specific project “**/ProjectName.csproj”
  2. A group of similarly named projects “**/*DataContracts.csproj”

You can target either the csproj or the nuspec. I usually target the csproj file but if you do ensure that you have a nuspec file of the same name.

Push the NuGet Package to your repository

In a previous life, I used myget. It was relatively cheap and was far superior to hosting your own NuGet server to setup a private repository. However, now VSTS has this functionality built in.

You might not see ‘Packages’ here at first. It’s actually a Visual Studio Team Services marketplace item but fear not you can get it for free if you have an MSDN subscription.

Once you do that your project will have a feed but you can add more if you want…

Once you do that you can use the ‘NuGet’ action’s push command to push all *.nupkg files to your target feed.

The target feed drop down will not be populated unless you have setup the marketplace item in VSTS. Alternatively you can use an external NuGet server but why bother? 😊


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