In one of the previous articles we mentioned the project NU. NU project was aimed to bring the power and flexibility of the Rubygems to the .NET community. Microsoft embraced this concept and introduced NuPack, now known as NuGet. In this article we will discuss the working of the NuGet framework and how it will benefits the developers.

Why NuGet?

You can always download the library and add a reference in your project. But this process is extremely cumbersome specially when you are downloading multiple libraries. Manual download also results in chaos when the assembly has a dependency on other assemblies.

NuGet solves this problem by providing a simple and easy to use interface for downloading the packages. NuGet also resolves the dependencies between the packages. NuGet hosts the packages at one common repository where users can contribute packages. In the next section we will take a closer look at using NuGet.

Downloading the Extension:

The first step is to download the NuGet extension which will be plugged into Visual Studio 2010. Use the following link to download the extension.

[NUGet Extension]

Make sure to close Visual Studio before running the extension. Once, the installation is finished you should be able to access the Package Manager using the following approaches:

Package Manager Console

To view the GUI for the Package Manager right click on "References" and select the option "Add Package Reference". The screenshot is shown below: 

NuGet in Action:

Although you can use NuGet through the graphical user interface but the recommended approach is to use the command line interface. Go to View -> Other Windows -> Package Manager Console to start NuGet console. Let's first list all the available packages. Run the following command fro NuGet Package Manager Console.

This will display a list of all the available packages supported by NuGet. You will notice that there are already quite a few packages available to download. In order to download and reference a package in your application you run the "Add-Package packagename" command as shown below:

The above command will add a reference to Elmah libraries in your project. It will also make the necessary changes in the Web.config file as shown below:

You just saved your self at least 5 minutes of performing the above work manually. You can also update the package using the following command:

As mentioned before the dependencies are automatically resolved using NuGet. The "nhibernate.core" package has dependencies on different packages. The NuGet makes sure to install all the dependennt packages along with nhibernate.core. The screenshot shows the dependencies being install along with the target package.  

By default the NuGet will install the latest version of the package.

You can remove the package along with its dependencies by using the -removedependencies option as shown below:


NuGet will revolutionize the package management in .NET community. Inspired by the Rubygems framework NuGet provides an ease of use and flexibility for managing packages in .NET applications. In the next article we will focus on how to build our own custom package for distribution.