Is there an easy way to automatically create a NuGet package from a Visual Studio 2015 project?

glopes picture glopes · Jan 26, 2016 · Viewed 10.2k times · Source

Before Visual Studio 2015, it was trivial to setup your project to automatically generate NuGet packages. Specifically, you did:

  1. Add a .nuspec file to your project
  2. Enable NuGet Package Restore in the Solution right-click context menu
  3. Edit the project .csproj file and set the build property <BuildPackage> to true

And that was it!

However, starting from VS 2015, MSBuild-integrated package restore has been removed and replaced by the new Automatic Package Restore. While these are all good news, it seems that setting the build property <BuildPackage> to true no longer triggers an automatic package build.

This is a major break of functionality! Is there a way to setup automatic builds of NuGet without using post-build events? Specifically, I'm looking for an MSBuild solution, as it forms the backbone of my build workflow.

Answer

Andriy K picture Andriy K · Jan 3, 2017

Try OctoPack: https://www.nuget.org/packages/OctoPack/

Just add nuget package to your project.

If you want to build it every time you build release, add to section <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|Whatever' "> next line:

 <RunOctoPack>true</RunOctoPack>

More information about finetuning can be found here: https://github.com/OctopusDeploy/OctoPack