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:
- Zip package is downloaded
- Hash is verified against the one provided by the hosting environment
- Content is unzipped
- 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é.
- Write a nuspec package specification - which is a little bit of xml containing name, version, authors, dependencies and optionally files.
- Run nupack.exe <myfile.nuspec> - from the nupack console which can be downloaded here.
- 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:
\lib\Net11\MyAssembly.dll
\Net20\MyAssembly.dll
\Net40\MyAssembly.dll
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.