An Introduction to NuGet

by admin 9. May 2012 17:09

NuGet Package ManagerGetting started with NuGet can be very confusing because there are really four parts to it with separate downloads. This post is an effort to make it easier to grasp and get started.

NuGet is one of those tools that you may not notice at first, but once you start using it you'll wonder how you ever got by without it. Not just a package manager, it is an ecosystem, a foundation upon which many different things can be built. A NuGet package can consist of assemblies, source code, config files, images, scripts, etc.

Do yourself a big favor and grab a copy of Pro NuGet by Maarten Balliauw and Xavier Decoster. From the book: "NuGet brings you all the benefits of any package manager: it takes care of dependency chains and versioning conflicts at installation time, and it facilitates finding, installing, updating and uninstalling packages on application level. Besides these common must-have functionalities, NuGet has much more to offer."

NuGet relieves us of the following headaches when trying to incorporate a third party library into our project:

1) Locate the application

2) Download the correct version of the package

3) "Unblock" the package

4) Unzip the files into our solution

5) Add an assembly reference

6) Update Web.Config with the correct entries

With NuGet, this is all done for us with one or two clicks!

Tooling

There are four main tools I use with NuGet, three by Microsoft and a third party tool called Package Explorer, created by Luan Nguyen, which I consider indispensable for routine everyday tasks.

 

Package Manager Console Microsoft
Use WPI*
Package Manager GUI Microsoft
Use WPI*
NuGet Command Line Tool Microsoft Download
Package Explorer Third Party Tool Download

* Web Platform Installer

 

1) Package Manager Console The Package Manager Console is a Visual Studio Extension that allows us to interact with NuGet from within Visual Studio using cmdlets ("commandlets") for routine operations.

 

Package Manager Console

 

2) Package Manager GUI The Package Manager GUI is a graphical user interface which allows us to visualize and edit package contents and metadata.

 

Package Manager GUI

 

3) NuGet Command Line Tool Interact with NuGet from a simple console window. Also used by CI systems and deployment environments to get or publish packages.

 

NuGet Command Line


4) Package Explorer NuGet Package Explorer is a ClickOnce application which allows creating and exploring NuGet packages easily. After installing it, you can double click on a .nupkg file to view the package content.

 

Package Explorer

More Information




I've previously shown how to set this in VS 2010. In the new VS 2011 beta, it's a little harder to find.

In order to change this behavior so that the tabs open to the right of any currently open tabs, go to the Tools drop down menu in Visual Studio and configure as follows:

  • Tools -> Options
  • Environment -> Tabs and Windows
  • Check the "Insert documents to the right of existing tabs" checkbox

 

Visual Studio 2011 Beta Tab Options



The entire blogosphere is buzzing over this release. I got to try it out for the first time last week while working though some of the hands-on labs at TechEd 2009 in Los Angeles. I was so engrossed in the lab content that I didn't pay it a lot of attention. BTW, Scott Hanselmann gave a great session entitled "Whirlwind Tour around .NET 4 (and Visual Studio) Beta 1 - check it out.

I decided to try it out this evening on a Windows Server 2008 VM, which had SQL Server 2005 installed. Everything went smoothly until after the first reboot when it bombed out. Then I remembered that there is a new Windows 4.5 Installer out so I downloaded that and tried again. Success! It only took about thirty minutes on a fairly fast machine.

VS 2010 Beta 1

 

I'm using VMWare Workstation, but if you are using Microsoft VMs then there is a really helpful video on Channel 9 which describes the download and installation of VS 2010 in depth. Either way, be sure to grab the installer first.

  * Visual Studio 2010 and .NET Framework 4 Beta 1Downloads

  * Visual Studio 2010 Product Information

What's in the works for the SharePoint Development IDE

Many months ago, the MVPs were invited to Redmond and shown the next generation of SharePoint development tools. Needless to say they were bound to a secrecy agreement and ever since have remained as tight-lipped as a duck's arse and that's watertight. So I was really dying to check out what SharePoint project templates might appear - unfortunately all I got was a blank box. However, it looks like the red-suspendered marketing folks have revealed some information on this in a VS 2010 marketing "overview" brochure (link at end of post). SharePoint goodies include:

"Project templates for list definitions, list instances, site definitions, workflows, event receivers, Business Data Catalog models, and content types"

So, it looks like the extensions are finally baked in where they belong. This is good news considering the the latest CTP of VSeWSS 1.3 has some problems with the 64-bit architecture.

"The feature and package designers in Visual Studio 2010 allow you to determine how your SharePoint application packages are assembled and deployed... without having to manually write the XML for the .wsp deployment packages."

Some further research revealed that much of this info was already out there if you knew where to look. So why were the SharePoint presenters at TechEd acting like they held the secrets of the universe? There was an announcement on some aspects of this last February on Somesegar's Blog - here you will find a link to a video interview with Reza Chitsaz, Senior Program Manager working on Office and Sharepoint tooling - this came out last November!

VS 2010 Beta 1

 

All hype aside, the new WPF-based IDE is really slick and I'm really looking forward to trying out some of the new Ajax 4.0 client controls :-)

The new SharePoint 2007 Marketing Website

VisualStudio2010_ProductOverview.pdf (1.03 mb)