Did You Forget to Create a Nuget Package Again?

The biggest problem with managing Nuget packages for internal applications is creating and publishing the correct versions for others to consume. It’s not hard, but it does require manual steps to update the Nuspec file, create the package, and publish it. For Nuget packages which are only occasionally updated, this probably isn’t a problem. There is adequate time to develop and test it, but when using packages to keep multiple solutions in sync by using the same libraries, and all of them are under active development, it can be easy to miss one of several steps.

Automating the process is relatively easy. The Nuget Package Explorer is great for creating packages through a GUI, but it doesn’t help with automating the process of creating packages after a build. For that, there is the Nuget Command Line.

When I install it, I put it in the following location:

The following scripts assume it will be located here. If not, simply modify them to point to the correct location.

Post Build Event

In the post build events text box under the Build Events tab in the project file place the following code. It needs to be all on one line with no carriage returns.

Create the CreateNugetPackage.ps1:

Modify the AssemblyInfo.cs file and change the AssemblyVersion to have a * to increment the build number (the last zero in the series). As future versions of the assembly are created in new branches, the other numbers should be changed to reflect the current version. (2.8.1.* for Major version 2, Minor Version 8, Patch Version 1)

Now everytime Visual Studio makes a successful build, a new Nuget package will appear in the appropriate folder next to the newly created assembly:


A full example project with it can be found on GitHub at this repo.