Add easy-to-add functionality you your .Net Development Project with NuGet

Charles Symons
Apr 6, 2011
Updated • Jan 1, 2015
Development
|
2

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.

Installing NuGet

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>
<p>
@Facebook.LikeButton("http://ghacks.net")

</p>

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.

Summary
software image
Author Rating
1star1star1star1stargray
no rating based on 0 votes
Software Name
NuGet
Operating System
Windows
Landing Page
Advertisement

Previous Post: «
Next Post: «

Comments

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

We love comments and welcome thoughtful and civilized discussion. Rudeness and personal attacks will not be tolerated. Please stay on-topic.
Please note that your comment may not appear immediately after you post it.