Automate creating a NuGet package from your Visual Studio project file

Dependencies lead to complexity. Complexity makes things unpredictable. When you change software and get unpredictable things happen. Rarely are these things good. That makes people fear change. Which makes it hard to harness change for the competitive advantage of the customer.

NuGet manages dependencies. This helps reduce complexity. Which makes it easier to predict what happens when I change software. Which means I don’t fear change. Which makes it easier for me to harness change for the competitive advantage of the customer.

This is a post about using NuGet to create packages. It is pretty simple to start using a GUI to build a package. If you make a change to a file this won’t get picked up by the tool. You’ll need to remove the old file and add it again. It gets dull pretty quickly. What is needed is some kind of automation.

NuGet supply a command-line utility to help. There is even a bootstrap version that updates itself every-time you use it. After I downloaded this stand-alone executable I created a new ASP.NET MVC project in Visual Studio. For the purpose of this exercise I don’t think it matters what kind of project you choose. In a command prompt, from you project folder type the following.

nuget spec

This will create a nuspec xml document in the root folder. This file holds the additional meta-data you’ll need later for creating the package. By default the file looks like this. The areas that need updating are highlighted pretty clearly. It is worth noting the author replacement token uses the company name in the project’s AssemblyInfo file.

<?xml version="1.0"?>
<package >
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2014</copyright>
    <tags>Tag1 Tag2</tags>

Now you are ready to automate the build. Run the following command. This will create a nupkg file based on the name of your project and version number.

nuget pack

You can exclude files using an option of the same name. That should be enough to get you started after that use the following links for more information.

This entry was posted in Sitecore. Bookmark the permalink.

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