Creating Packages

Although it is very easy to consume packages with NuGet, there wouldn't be any packages to consume if people didn't also create them. This is why the NuGet team made package creation as simple as possible.

Before you create a package, make sure to download the NuGet.exe command-line utility from the NuGet CodePlex website at http://nuget.codeplex.com/. Copy NuGet.exe to a more central location on your hard drive and add that location to your PATH environment variable.

NuGet.exe is self-updatable via the Update command. For example, you can run:

NuGet.exe update -self

or use the short form:

Nuget u -self

This backs up the current version of NuGet.exe by appending the .old extension to its file name, and then replaces it with the latest version of NuGet.exe.

Once you have NuGet.exe installed, there are three main steps to create a package:

1. Organize the package contents into a convention-based folder structure.
2. Specify the metadata for the package in a .nuspec file.
3. Run the NuGet.exe Pack command against the .nuspec file:
Install-Package NuGet.CommandLine

Packaging a Project

In many cases, a package contains a single assembly that maps nicely to a Visual Studio project (a .csproj or .vbproj). In this case, creating a NuGet package is trivially easy. From a command prompt, navigate to the directory containing your project file and run the following command:

NuGet.exe pack MyProject.csproj -Build

If the directory contains only a single project file, ...

Get Professional ASP.NET MVC 4 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.