Add easy-to-add functionality you your .Net Development Project with NuGet
NuGet is a Visual Studio extension that enables you to download and use shared code libraries with the Microsoft development community.
This is Microsoftâ€™s attempt to benefit from a large development community and pool of shared code, a concept enjoyed by many open source communities such as Drupal and Ruby on Rails.
The extension will manage the installation of libraries, files, references and any necessary configuration in the form of â€œpackagesâ€ that can be added or removed.
NuGet is a free, open source developer focused package management system for the .NET platform intent on simplifying the process of incorporating third party libraries into a .NET application during development
With the Release of NuGet 1.2 the system has matured by allowing packages to specify the version of the .Net framework they are referencing types from, automatic binding redirects for the times where a package needs a different assembly version from the one that is currently being used as well as allowing the package to separate libraries for different platforms such as Windows Phone 7.
In this post Iâ€™ll step though how to install NuGet and utilize one of the many packages available. In a future post Iâ€™ll descript how to create your own package to share with the community.
NuGet runs on any commercial edition of Visual Studio 2010 or Visual Studio Express 2010 Visual Web Developer. Other express editions are not currently supported.
To install NuGet, open the Extension Manager in the tools menu in Visual Studio.
Click the Online Gallery on the left side, then type â€œNuGetâ€ in the Search Online Gallery field.
Click the Download button on the NuGet Package Manager. After the installation you will need to restart Visual Studio
Using a package
After youâ€™ve installed NuGet you have access to a library of hundreds of community developed packages. A gallery of which can be found here: http://nuget.org/
To install a package, right-click on the project you wish to add a package to and select â€œAdd Library Package Referenceâ€¦â€, click â€œonlineâ€ and search for the name of the package to use.
An example is the Fackbook.Helper package that makes it easy to add interactive Facebook controls. http://facebookhelper.codeplex.com/
Once you click install, the files included in the package are downloaded and automatically added to your project. A packages.config will also appear in your project and will display the packages used.
I have found however that in the case of some packages, not all the assemblies the package uses are added to the projectâ€™s references. In these cases Iâ€™ve had to manually add the references they need. Even then, sometimes not all the required assemblies are in the Global Assembly Cache (GAC). In these cases you should switch Copy Local in the referenced DLLâ€™s properties to True so that the assembly is coped to your bin folder at build time.
Now once the Fackbook.Helper package is installed, I can easily add a facebook â€œlikeâ€ button with the razor code:
@Facebook.LikeButton(URL to like)
ViewBag.Title = "Home Page";
<h2>NuGet 1.2 Facebook.Helper Test</h2>
The result is a Facebook like button with precious little effort.
NuGet is in its relative infancy but already has over a thousand packages to explore. It is a welcome recognition by Microsoft of the strength of an open source community and the benefits for its developers.
New users should look at the Getting Started page and the Nuget documentation.Advertisement