The Marvels of NuGet

How Don Kiely got hooked on Microsoft's package management extension to Visual Studio

Microsoft has been making a lot of noise lately about NuGet, their still-new package management extension to Visual Studio. I have to admit that I just didn't "get it" for quite a long time after they announced it. It seemed like a nice little feature, but not worth anywhere near the attention it was getting. So it finds and automatically installs packages into a project. That's kind of nice, but it just didn't rock my world.

Okay, so maybe I'm a bit slow on the uptake on some things. But last week I was forced to sit through a few sessions about it, scattered over a few days at a conference. Well, maybe "forced" is too harsh a word—I would have picked other topics at those times had any interesting ones been available. As it was, I was dragged, initially kicking and screaming but later quite willingly, into the fold of NuGet believers. This is one rockin' cool tool.

Officially, NuGet is a free, open source package management system that simplifies incorporating third-party libraries into a .NET application (not just ASP.NET). That description is a bit dull—which might be why I didn't catch on to NuGet for a while. In reality, NuGet is a way to download and install just about any kind of components that someone cares to package together in a form NuGet can work with. Once the package is uploaded and you've installed NuGet in Visual Studio, you can search for and automatically download and install the package in a project. And it's that last part that is the best part: A properly designed package will do whatever is necessary to get the library configured for you. That might mean adding some elements to the project's config file, putting files in their proper locations within the project, or whatever else is necessary. No longer do you need to do manual installations to get things working right, so you're free of all the tedious work needed to get things set up. And if a package has any dependencies, NuGet can install the dependencies as well. Automatically.

Packages I've Used with NuGet
I have to admit that the packages that got my attention, even though they aren't themselves hard to install, are the jQuery Library and quite a few jQuery extensions. In the figure below, I've started NuGet from Visual Studio, selected the Online tab on the left, and searched for "jquery" in the search box in the upper right. As you can see on the first of five pages or results, you can automatically install the core jQuery Library and the current vsdoc file for IntelliSense in the JavaScript editor in Visual Studio, as well as various other plug-ins. What's really interesting is that someone on the jQuery UI Team has taken the time to put together NuGet packages for the major components of jQuery UI, saving you the trouble of going to the jQuery UI website and building your own custom download and installing it manually.

NuGet packages for jQuery components
NuGet packages for jQuery components

Perhaps a better example of a package to get excited about using NuGet with is ELMAH (Error Logging Modules and Handlers), a drop-dead simple way to add logging functions to a .NET project. It uses HTTP modules and handlers to do its magic, which are a bit involved to install correctly. Getting it set up requires some .config file entries in addition to putting the DLL in the right place. It's not rocket science, but it's more manual than it could be. When you use NuGet to install ELMAH, it installs the files and does all the configuration for you. Done. Now go run the project and have the benefit of ELMAH. Of course, you can certainly tweak the configuration after installation all you want.

Even better, NuGet keeps track of the packages you have installed in a project and can automatically take care of updating them whenever you want. A package could have some breaking changes, so you'll need to test new versions carefully, but at least the tedious drudgery of getting a library installed is no longer necessary.

Installing and Running NuGet
You can install NuGet using the Visual Studio Extension manager, itself a big time saver for configuring a development machine. Then you can run NuGet by selecting Tools, Library Package Manager, Add Library Package Reference from the Visual Studio main menu. You can install new packages from here or look at the packages you have installed to see which have updates. And if you're more of the PowerShell type, you can use the Package Manager Console menu item to open a PowerShell 2.0 console right in Visual Studio and do all your NuGet work from there using cmdlets. I'm usually not a command-line kind of guy anymore, but one presentation last week was all from the console, and it was pretty amazing what the presenter could accomplish in no time at all.

The interesting thing is that anyone can create a NuGet package and upload it to the gallery. You don't have to be the library's author, although it is certainly courteous to ask the author, as long as the library is freely distributable.

If you use open source libraries and other tools in your applications, NuGet is a no brainer. Go download it now, and let it help you be more productive immediately.

NuGet on Codeplex: The home of NuGet, with documentation and lots of other information. You can also grab the NuGet source code here, if you are so inclined.

NuGet Gallery: Download and install NuGet if you don't want to use the Visual Studio Extension Gallery, and use a Web application to explore the available packages. There are 988 packages available as I write this, which includes multiple versions of some packages.

You've Been Haacked: Phil Haack is probably NuGet's biggest and noisiest advocate within Microsoft. There is lots of good information on his blog about doing some off the wall things with NuGet and other Microsoft technologies.

Don Kiely ([email protected]), MVP, MCSD, is a senior technology consultant, building custom applications and providing business and technology consulting services. His development work involves SQL Server, Visual Basic, C#, ASP.NET, and Microsoft Office.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.