NuGet is a new tool implemented in Visual Studio 2010 as both an extension and command line tool, as well as in WebMatrix as a web admin tool for package management. You can download and install NuGet packages directly into any Visual Studio 2010 project or WebMatrix website, without having to leave the software! NuGet packages are also available for use in non web projects in Visual Studio such as WPF, Silverlight, WP7, or Winforms projects. And that's not all, you can even use NuGet without Visual Studio or WebMatrix, making it quite versatile.
NuGet solves a very common problem in software development: obtaining, installing and managing external libraries.
Traditionally, developers who were using Visual Studio would have to do most, if not all or more of the following, to find and install 3rd party libraries or, at times, libraries built by their team members:
- Open a browser and your favorite search engine, then search for the libraries you want, often guessing at the library name.
- Spend a few to several minutes of searching for the correct library and download link.
- Identify the correct download version, OS and 32/64 bit support.
- Download, extract and run the installer, if there is an installer. Otherwise, follow multi-step installation directions.
- Reference in Visual Studio.
Then you're finally ready to code! With NuGet however, you can skip over all the steps and go straight to #5 - Reference in Visual Studio. Your coffee won't even have a chance to get cold.
But before you can get to all this NuGet-y goodness (and hot coffee), you need to get NuGet itself, which is just as easy as using it.
Where do I get NuGet?
You have to start somewhere, and that's getting NuGet in the first place. Open the editor of your choice: Visual Studio and/or WebMatrix. NuGet works with both editors, even if both are installed on the same machine.
In Visual Studio 2010; open the Extensions Manager utility from the Tools menu and search for NuGet, then double click to install and reference. NuGet is installed in WebMatrix by default and you can access it by using a web admin tool, described later in this post.
You can also download and install NuGet directly from CodePlex.
Using NuGet with Visual Studio 2010
After NuGet is installed, you can start searching for packages by using the Package Management Console or by using the new "Add Library Package Reference" menu item in the context menu located on the Project's References node of Solution Explorer, as the following image demonstrates:
The search box is the quickest way to locate and install the NuGet packages. You can use the search box located in the top right corner of the extensions dialog to perform a partial word search or browse by category along the left side of the dialog as shown below.
You may have noticed that the NuGet package manager UI uses the same dialog as the extensions manager above does. When you find a library you wish to use, simply double click on the package listed in the dialog window and the package will be installed (or uninstalled if already installed) directly into the current Visual Studio 2010 project. Note: At this time, there's no installation across projects, so you'll need to use the Add Library Package tool for each reference you want.
Look under the References node for the assembly references that were added by NuGet. Here's an updated look at the references after installing the MvcContrib framework from CodePlex.
And that's it! You can immediately start coding to the newly referenced package resources.
Using NuGet with WebMatrix
In WebMatrix NuGet is implemented via a web interface, rather than as part of the IDE. To access NuGet, browse the application from the IIS Express tray icon then append "_/admin" to the URL (after the port number and ending slash).
Alternatively you could run any web page in the project and adjust the URL to point to the admin web page. The page will prompt for a password or ask you to create one if this is your first visit to the admin site.
The Package Manager along with a Web Debugger are available via the Web Pages Administration utility. To download and install NuGet packages here, navigate to the package manager page and select the package(s) for installation (or uninstallation). Just as with Visual Studio, installed and online packages in NuGet work for this web site only.
You can investigate what's been installed by examining the \packages\ folder under the \App_Data\ folder in WebMatrix. Don't worry if you see a lot of extra folders after an install; often packages come with documentation, code samples, and the like, as outlined in the snapshot below:
Finding libraries for your .NET projects doesn't get any easier than using NuGet. And when you're ready to distribute libraries to your teammates or on the net, you can create your own NuGet packages and post to familiar sites such as CodePlex or as well as your own private feeds.
As a parting note, whenever I hear the word NuGet, I think of delicious chocolate bars. mmmmmmmm Nuget.