Creating Packages

Although consuming packages is very easy with NuGet, there wouldn't be any packages to consume if people didn't also create them. This is why the NuGet team is focused on making sure that creating packages is 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 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

or use the short form:

Nuget u

to back up the current version of NuGet.exe by appending the .old extension to it and replace it with the latest version of NuGet.exe.

Once you have NuGet.exe installed, creating a package requires three main steps:

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

Folder Structure

By default, the NuGet Pack command recursively includes all the files in the folder where the specified .nuspec file is located. It is possible to override this default by specifying the set of files to include within the .nuspec file.

A package consists of three types of files as outlined in Table 10.1.

Table 10.1: Package File Types

Folder Description
lib Each assembly (.dll

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

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.