An Introduction to NuGet

by admin 9. May 2012 17:09

NuGet Package ManagerGetting started with NuGet can be very confusing because there are really four parts to it with separate downloads. This post is an effort to make it easier to grasp and get started.

NuGet is one of those tools that you may not notice at first, but once you start using it you'll wonder how you ever got by without it. Not just a package manager, it is an ecosystem, a foundation upon which many different things can be built. A NuGet package can consist of assemblies, source code, config files, images, scripts, etc.

Do yourself a big favor and grab a copy of Pro NuGet by Maarten Balliauw and Xavier Decoster. From the book: "NuGet brings you all the benefits of any package manager: it takes care of dependency chains and versioning conflicts at installation time, and it facilitates finding, installing, updating and uninstalling packages on application level. Besides these common must-have functionalities, NuGet has much more to offer."

NuGet relieves us of the following headaches when trying to incorporate a third party library into our project:

1) Locate the application

2) Download the correct version of the package

3) "Unblock" the package

4) Unzip the files into our solution

5) Add an assembly reference

6) Update Web.Config with the correct entries

With NuGet, this is all done for us with one or two clicks!


There are four main tools I use with NuGet, three by Microsoft and a third party tool called Package Explorer, created by Luan Nguyen, which I consider indispensable for routine everyday tasks.


Package Manager Console Microsoft
Use WPI*
Package Manager GUI Microsoft
Use WPI*
NuGet Command Line Tool Microsoft Download
Package Explorer Third Party Tool Download

* Web Platform Installer


1) Package Manager Console The Package Manager Console is a Visual Studio Extension that allows us to interact with NuGet from within Visual Studio using cmdlets ("commandlets") for routine operations.


Package Manager Console


2) Package Manager GUI The Package Manager GUI is a graphical user interface which allows us to visualize and edit package contents and metadata.


Package Manager GUI


3) NuGet Command Line Tool Interact with NuGet from a simple console window. Also used by CI systems and deployment environments to get or publish packages.


NuGet Command Line

4) Package Explorer NuGet Package Explorer is a ClickOnce application which allows creating and exploring NuGet packages easily. After installing it, you can double click on a .nupkg file to view the package content.


Package Explorer

More Information

When uploading a file, you will usually want to check that the extension is of the correct type:

if ((String.Compare(fileExt, ".pdf", true)) == 0) {...}

However, the above code will not work if the letters are in a different case.

This is a better way which ignores the case:

if ((fileExt.IndexOf("pdf", StringComparison.OrdinalIgnoreCase) == 0)) {...}


An even better way (counteracts input such as "pdf2", etc.)

if (string.Equals(fileExt, ".pdf", StringComparison.OrdinalIgnoreCase)) {...}

I've previously shown how to set this in VS 2010. In the new VS 2011 beta, it's a little harder to find.

In order to change this behavior so that the tabs open to the right of any currently open tabs, go to the Tools drop down menu in Visual Studio and configure as follows:

  • Tools -> Options
  • Environment -> Tabs and Windows
  • Check the "Insert documents to the right of existing tabs" checkbox


Visual Studio 2011 Beta Tab Options