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.

Alt

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’.

Alt

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.

Alt

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

Alt

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

Alt

Alt

You can use the following syntax to select:

A specific project “/ProjectName.csproj” 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.

Alt

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…

Alt

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

Alt

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? 😊