Thursday, June 9, 2016

Golden NuGet

One of the hassles of software engineering is finding the right libraries for your project. Need jQuery? Until now, you had better be prepared to scrounge the web for a jQuery host, download an archive containing the code, unzip the files, copy them to your project directory, add the references to your project, and then hope and pray that you've got the correct version. Sound like a headache? Trust me, it is... and that's just jQuery, one of the more popular and readily-available libraries that many engineers use on a daily basis. Need bootstrap? iTextSharp? jQuery UI? AngularJS? Be prepared for more of the same. Luckily, Microsoft recognizes this problem and has prepared a nifty little solution that takes the pain out of locating and managing these commonly-used libraries.

This solution is a service called NuGet (pronounced "new-get"). NuGet consists of two distinct components, the first of which is the NuGet Gallery, which is essentially a warehouse for commonly-used libraries for .NET, such as jQuery, bootstrap, and others. Using NuGet, developers don't have to search across the web to find the libraries they need; instead, the NuGet Gallery functions as a one-stop source for these libraries and others, housing over 600,000 different libraries (called "packages" by NuGet) in all at the time of this writing.

The second component of NuGet is the NuGet Package Manager, a plug-in that is included with Visual Studio. With the NuGet Package Manager, you don't even have to leave your IDE to get the libraries you need. Better yet, in addition to downloading your desired packages on demand, the NuGet Package Manager will also automatically install your packages to your solution by copying the code files to the appropriate directories and adding the references to your project file. Still need jQuery? Instead of following the tedious steps I mentioned earlier, simply open your project in Visual Studio, go to 'Tools' -> 'NuGet Package Manager' -> 'Package Manager Console', and then type the command 'Install-Package jQuery'. There ya go! NuGet Package Manager will automatically download the latest version of jQuery from the NuGet Gallery and install it to your project. Pretty nice, eh?

Not only does NuGet make your life easier by streamlining the process of installing packages, but it makes maintenance a breeze, too. Let's say some time goes by and you want to make sure that you're using the latest version of jQuery (or any other package). NuGet Package Manager can check for available updates to all of the NuGet packages included in your project and install them automatically. To do this, simply re-open the NuGet Package Manager Console and type the command 'Update-Package'. Presto! All of your NuGet packages are now updated to the latest available version.

Finally, NuGet makes removing packages easy, too. Eliminating unneeded libraries and cleaning up deprecated references is a necessary and often tedious process. NuGet takes the pain out of this by "cleaning up" when a package is uninstalled by removing the package code and references automatically. Decided that you don't need that jQuery package? Just open the NuGet Package Manager Console and type the command 'Uninstall-Package jQuery'. NuGet will now remove all of the jQuery code and references, leaving your project as sparkly-clean as it was to start.

In summary, NuGet is a very powerful service that does a lot to make the jobs of .NET software engineers easier and improves the overall integrity of a solution. The degree of convenience that NuGet brings to package installation, maintenance, and uninstallation cannot be understated and I applaud Microsoft for supporting their developers by releasing such a great tool. Now, if they can just develop one that'll automatically prepare all of my documentation for me...