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 > <metadata> <id>$id$</id> <version>$version$</version> <title>$title$</title> <authors>$author$</authors> <owners>$author$</owners> <licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl> <projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl> <iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>$description$</description> <releaseNotes>Summary of changes made in this release of the package.</releaseNotes> <copyright>Copyright 2014</copyright> <tags>Tag1 Tag2</tags> </metadata> </package>
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.