NuPack 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.
There are a large number of useful 3rd party open source libraries out there for the .NET platform, but for those not familiar with the OSS ecosystem, it can be a pain to pull these libraries into a project.
NuPack is a free open source package manager that makes it easy for you to find, install, and use .NET libraries in your projects. It works with all .NET project types (including, but not limited to, both ASP.NET Web Forms and ASP.NET MVC).
NuPack enables developers who maintain open source projects (for example, projects like Moq, NHibernate, Ninject, StructureMap, NUnit, Windsor, RhinoMocks, Elmah, etc) to package up their libraries and register them with an online gallery/catalog that is searchable. The client-side NuPack tools – which include full Visual Studio integration – make it trivial for any .NET developer who wants to use one of these libraries to easily find and install it within the project they are working on.
NuPack handles dependency management between libraries (for example: library1 depends on library2). It also makes it easy to update (and optionally remove) libraries from your projects later. It supports updating web.config files (if a package needs configuration settings). It also allows packages to add PowerShell scripts to a project (for example: scaffold commands). Importantly, NuPack is transparent and clean – and does not install anything at the system level. Instead it is focused on making it easy to manage libraries you use with your projects.
NuPack is itself an open-source project. The Outercurve Foundation (formerly CodePlex Foundation) today announced the acceptance of the NuPack project to the ASP.NET Open Source Gallery. Developers - both inside and outside Microsoft – will contribute features, bug fixes and patches to NuPack.
Our goal with NuPack is to make it as simple as possible to integrate open source libraries within .NET projects. It will be supported in all versions of Visual Studio. You can start using the first developer preview of it today.
Let’s take ELMAH as an example. It’s a fine error logging utility which has no dependencies on other libraries, but is still a challenge to integrate into a project. These are the steps it takes:
- Find ELMAH
- Download the correct zip package.
- “Unblock” the package.
- Verify its hash against the one provided by the hosting environment.
- Unzip the package contents into a specific location in the solution.
- Add an assembly reference to the assembly.
- Update web.config with the correct settings which a developer needs to search for.
And this is for a library that has no dependencies. Imagine doing this for NHibernate.Linq which has multiple dependencies each needing similar steps. We can do much better!
NuPack automates all these common and tedious tasks for a package as well as its dependencies. It removes nearly all of the challenges of incorporating a third party open source library into a project’s source tree. Of course, using that library properly is still up to the developer.
Here's a small sampling of what NuPack can do:
To get started using NuPack, you’ll need Visual Studio 2010 installed. NuPack is implemented as a Visual Studio Extension (VSIX). Download the latest release and double click on the NuPack.Tools.vsix file to launch the NuPack Visual Studio Extension Installer.
Launching the Add Package Reference Dialog
There are two ways to interact with the package manager:
- The Add Package Reference Dialog GUI, which gets you started quickly and easily.
- The Powershell based Package Console, for when you need more power and tools.
Let’s start with the Add Package Reference dialog.
1. First, create a new VB.NET or C# application in Visual Studio.
By pure random chance, I’ve chosen to create an ASP.NET MVC 2 application.
2. Right click on the References node within the Solution Explorer and select the Add Package Reference menu option.
This will bring up the Add Package Reference dialog, seen here (click for larger).
The dialog allows you to page through the list of available NuPack packages as well as perform searches against the list of online package. The list of packages is being pulled from an ATOM feed, which can be configured using the Settings button.
Installing a Package
Installing a package is very easy now that we have the dialog up and running.
1. Find the package.
You can either page through the results, or use the search feature. In the Search Online box, type in “elmah”. You should see the following filtered view.
2. Double click the Elmah entry.
That’s it! Behind the scenes, NuPack added the Elmah assembly into a subfolder of your solution, added an assembly reference to that assembly, and also modified your Web.config file with minimal settings to get you started. You’ll probably want to change those settings for a real application.
But you are all set to start using and programming against ELMAH. Visit /elmah.axd within your project to try it out.
Using the Package Console
For those who prefer using the keyboard, NuPack also includes a PowerShell based console for managing packages. The console enables a feature that isn’t available via the Add Package Reference dialog as you’ll see.
To get to the Package Console window, select the View | Other Windows | Package Manager Console menu option.
1. Listing available Packages (List-Package
)
Use the List-Package
command to list available packages as seen in the screenshot. Note that you get intellisense within the console so if you type List
and hit tab, you’ll see a list of options.
This queries the package source and lists the available packages. The nice thing about using PowerShell is that it provides a powerful way of filtering and composing commands. For example, if I only want to list the Id and Description, I can pipe the command to the select
command List-Package | select Id, Description
2. Installing a package (Add-Package
)
To install a package, run the Add-Package
command and specify the Id
.
The package will be installed to the default project (specified in the console). You can use the –Project
flag to explicitly specify the project.
The console also supplies Intellisense for the package Id.
3. Installing new Console Commands
Earlier, I mentioned that the package console enables a feature that’s not available in the dialog. The feature in question is the ability for a package to contain tools which add new commands to the console.
For example, if you install the prototype Mvc-Scaffold package, a new Add-MvcView
command is now available to be called from the console.
This provides a powerful way of extending and automating Visual Studio. In the future, this package might contain commands for completely scaffolding a web application from an object model or a database.
Scott Guthrie has posted a good blog on the topic as has Scott Hanselman.
NuPack – Open Source Package Manager for .NET
NuPack is a free open source package manager that makes it easy for you to find, install, and use .NET libraries in your projects. It works with all .NET project types (including, but not limited to, both ASP.NET Web Forms and ASP.NET MVC).
NuPack enables developers who maintain open source projects (for example, projects like Moq, NHibernate, Ninject, StructureMap, NUnit, Windsor, RhinoMocks, Elmah, etc) to package up their libraries and register them with an online gallery/catalog that is searchable. The client-side NuPack tools – which include full Visual Studio integration – make it trivial for any .NET developer who wants to use one of these libraries to easily find and install it within the project they are working on.
NuPack handles dependency management between libraries (for example: library1 depends on library2). It also makes it easy to update (and optionally remove) libraries from your projects later. It supports updating web.config files (if a package needs configuration settings). It also allows packages to add PowerShell scripts to a project (for example: scaffold commands). Importantly, NuPack is transparent and clean – and does not install anything at the system level. Instead it is focused on making it easy to manage libraries you use with your projects.
NuPack is itself an open-source project. The Outercurve Foundation (formerly CodePlex Foundation) today announced the acceptance of the NuPack project to the ASP.NET Open Source Gallery. Developers - both inside and outside Microsoft – will contribute features, bug fixes and patches to NuPack.
Our goal with NuPack is to make it as simple as possible to integrate open source libraries within .NET projects. It will be supported in all versions of Visual Studio. You can start using the first developer preview of it today.
A Simple NuPack Scenario – Enabling ELMAH
As a simple example to show off what NuPack enables – let’s assume we are working on a brand new ASP.NET application and want to use the popular open-source “ELMAH” library to log and report errors with our site. To install ELMAH today, you’d need to manually download it, unzip it, add a reference to your project, make sure you have source control bindings for the library setup correctly, and update the web.config file of your application to include the Elmah HttpModule entries. All doable – but a little tedious.
With NuPack installed, you can simply open the new “Package Manager Console” that NuPack enables inside VS and type “Add-Package elmah” within it:
Typing "Add-Package elmah” causes NuPack to check an online feed to locate the Elmah library, download it, add a reference of it to your current project, and automatically add the appropriate Elmah registration entries within your application’s web.config file:
And now we have Elmah setup and installed for our project, and error report logging enabled. No additional manual steps required to make it work.
Learn More About NuPack
Check out the following links to learn more about NuPack and some of the many scenarios it enables:
- Scott Hanselman’s NuPack Tutorial
- Phil Haack’s NuPack Post
- Bill Simser’s Post on NuPack (he is a non-Microsoft dev working on it)
- Rob Reynold’s “Evolution of Package Management on .NET” Post (Rob is one of the leaders of the Nu project and is on the NuPack team)
- David Ebbo’s NuPack Post
- Documentation and tutorials on nupack.codeplex.com
.NET and Open Source
We think NuPack will be a fundamental component of the .NET stack going forward. It will encourage more .NET developers to use open-source libraries. Having a standard package manager integrated into millions of copies of Visual Studio will hopefully also encourage the creation of more open source projects with .NET.
References
http://www.hanselman.com/blog/IntroducingNuPackPackageManagementForNETAnotherPieceOfTheWebStack.aspx
No comments:
Post a Comment