NuPack - what you need to know as a developer

by DotNetNerd 19. October 2010 11:24

A little while ago I blogged about NuPack which is a package management system that Microsoft have released in a CTP1. The cool thing about NuPack is that solves the open source dependency hell, is really easy to use, and it comes as a Visual Studio Extension. After installing the extension you can install packages through a "add reference" like dialog, or through the Package Manager Console. 

On top of that it is very easy to make your own packages, and to host your own repository - which is why I decided to write this post. This provides you with an easy way to distribute shared components between teams and projects. 

Basics - what does NuPack do?

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

  1. 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 

Packing your own lunch - or launching your own package...

Making your own package is easy as 1-2-3 - just to use a well worn cliché. 

  1. Write a nuspec package specification - which is a little bit of xml containing name, version, authors, dependencies and optionally files.
  2. Run nupack.exe <myfile.nuspec> - from the nupack console which can be downloaded here.
  3. Copy the package to a fileshare (local) or publish it to nupackpackages (public) - done! 
The reason why I write that you can optionally describe which files are included is that if you follow the below conventions you don't have to write anything.  
  • 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
Building on this you can differentiate between targeted frameworks following this naming convention: lib\{framework name}{version}  

lib/40 –> .NETFramework 4.0
lib/SL4 –> Silverlight 4.0
lib/net20 –> .NETFramework 2.0

Gives you:

According to the codeplex site they plan to write tasks for MsBuild, NAnt, etc. for integrating the creation of NuPack packages into a build process. So basically this will be close to transparent once it is set up.

Managing repositories in Visual Studio 2010

If you wish to add a repository this can be done either through the Package Management Console or the NuPack GUI.

To change repository 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>

To change repository using the NuPack GUI right click on any project and click "Add Package Reference...". Then click settings in the lower left corner. This will bring up the setting dialog where you can fill in the path to the feed server or physical path, and select the default repository. 



Who am I?

My name is Christian Holm Diget, and I work as an independent consultant, in Denmark, where I write code, give advice on architecture and help with training. On the side I get to do a bit of speaking and help with miscellaneous community events.

Some of my primary focus areas are code quality, programming languages and using new technologies to provide value.

Microsoft Certified Professional Developer

Microsoft Most Valuable Professional

Month List

halk tv