NuGet – New Visual Studio extention helps Get packages

NuGet (pronounced: “new get”) which was at first called NuPack is a package management system that Microsoft have released in a CTP2. The cool thing about NuGet is that it makes it easy to add open source components to your solution, as well as providing you with a simple way to distribute your own components.

So next time you need to use Ninject, NHibernate or some of your other favorite libraries I recommend that you take a look at NuGet, and save yourself some time and headackes.

The idea originates from the NU project on googlecode but it comes as a Visual Studio Extension. Installing the extension is easy as can be and after that you can install packages through a “add reference” like dialog, or through the Package Manager Console.

On top of that it is easy to make your own packages, and to host your own repository – which provides you with an easy way to distribute shared components internally between teams.

The basics of NuGet

You can add a package in the same way as you add references, by just going through the add package reference dialog just below the good old trusty add references dialog.

If you are the kind og guy who likes consoles you can use the package manager console. The commands you need to get started are the self explanatory List-Package and Add-Package <packagename>. This comes with intellisence so you don’t need to remember all your projects exact names.

The process is quite simple with only a few overall steps that occur when a package is installed:

  1. A Zip package is downloaded
  2. Hash is verified against the one provided by the hosting environment
  3. Content is unzipped
  4. References are added to the assemblies

No magic here – very simply does what you would otherwise do yourself, along with keeping track of references to other required packages which are also added as needed.

Packing your own lunch – or launching your own package…

As I wrote in the introduction making your own package is very easy.

  1. Write a nuspec package specification – which is xml describing name, version, authors, dependencies and optionally files. Schema available at the codeplex site.
  2. Run nupack.exe <myfile.nuspec> – from the nupack console which can be downloaded here.  Im guessing this will be renamed shortly.
  3. Put the package on a fileshare (local) or publish it to nupackpackages (public) – another site that will probably be renamed soon.
  4. And your DONE!

Describing the files is optional because you can choose to just follow conventions instead so you don’t have to write anything.  The conventions describe the folders that can be added and where the files are then copied. The conventions are:

  • tools – the tools folder of a package will be added to $env:Path (PATH) when the package is installed
  • content – these files will be copied to the site root on install
  • lib – dlls under this folder will become assembly references on install

To differentiate between targeted frameworks you can follow this naming convention: lib\{framework name}{version}

{framework name} can be: NET, NETFramework, .NET which become .NETFRAMEWORK or SL which becomes Silverlight.

To give an example this means that “lib/40” targets the .NETFramework 4.0 and will be placed as “\lib\Net40\MyAssembly.dll”

According to the codeplex site Microsoft will write tasks for MsBuild, NAnt, etc. so it will possible to integrate into your buildprocess.

Configuring repositories in Visual Studio 2010

To choose a repository can either be done through the Package Management Console or the NuGet GUI.

From the Package Management Console go to View -> Other Windows -> Package Manager Console and run the command Update-PackageSource <path to server or physical path>

From the NuGet GUI right click on any project and click “Add Package Reference…”. Next click the settings button in the lower left corner. This givces you a dialog where you can fill in the path to the feed server or physical path, and select the default repository.

Nuget

Christian Holm Nielsen
Vertica A/S

Kategorier: Udvikling

Tagged as: ,

Skriv et svar

Udfyld dine oplysninger nedenfor eller klik på et ikon for at logge ind:

WordPress.com Logo

Du kommenterer med din WordPress.com konto. Log Out / Skift )

Twitter picture

Du kommenterer med din Twitter konto. Log Out / Skift )

Facebook photo

Du kommenterer med din Facebook konto. Log Out / Skift )

Google+ photo

Du kommenterer med din Google+ konto. Log Out / Skift )

Connecting to %s