Introducing NuGet Package Manager

asp.net mvc, code, open source, nuget 0 comments suggest edit

NuGet (recently renamed from NuPack) is a free open source developer focused package manager intent on simplifying the process of incorporating third party libraries into a .NET application during development.

After several months of work, the Outercurve Foundation (formerly CodePlex Foundation) today announced the acceptance of the NuGet project to the ASP.NET Open Source Gallery. This is another contribution to the foundation by the Web Platform and Tools (WPT) team at Microsoft.

Also be sure to read Scott Guthrie’s announcement post and Scott Hanselman’s NuGet walkthrough. There’s also a video interview with me on Web Camps TV where I talk about NuGet.

nuget-229x64Just to warn you, the rest of this blog post is full of blah blah blah about NuGet so if you’re a person of action, feel free to go:

Now back to my blabbing. I have to tell you, I’m really excited to finally be able to talk about this in public as we’ve been incubating this for several months now. During that time, we collaborated with various influential members of the .NET open source community including the Nu team in order to gather feedback on delivering the right project.

What Does NuGet Solve?

The .NET open source community has churned out a huge catalog of useful libraries. But what has been lacking is a widely available easy to use manner of discovering and incorporating these libraries into a project.

Take ELMAH, for example. For the most part, this is a very simple library to use. Even so, it may take the following steps to get started:

  1. You first need to discover ELMAH somehow.
  2. The download page for ELMAH includes multiple zip files. You need to make sure you choose the correct one.
  3. After downloading the zip file, don’t forget to unblock it.
  4. If you’re really careful, you’ll verify the hash of the downloaded file against the hash provided by the download page.
  5. The package needs to be unzipped, typically into a lib folder within the solution.
  6. You’ll then add an assembly reference to the assembly from within the Visual Studio solution explorer.
  7. Finally, you need to figure out the correct configuration settings and apply them to the web.config file.

That’s a lot of steps for a simple library, and it doesn’t even take into account what you might do if the library itself depends on multiple other libraries.

NuGet automates all of these common and tedious tasks, allowing you to spend more time using the library than getting it set up in your project.

NuGet Guiding Principles

I remember several months ago, Hot on the heels of shipping ASP.NET MVC 2, I was in a meeting with Scott Guthrie (aka “The Gu”) reviewing plans for ASP.NET MVC 3 when he laid the gauntlet down and said it was time to ship a package manager for .NET developers. The truth was, it was long overdue.

I set about doing some research looking at existing package management systems on other platforms for inspiration such as Ruby Gems, Apt-Get, and Maven. Package Management is well trodden ground and we have a lot to learn from what’s come before.

After this research, I came up with a set of guiding principles for the design of NuGet that I felt specifically addressed the needs of .NET developers.

  1. Works with your source code. This is an important principle which serves to meet two goals: The changes that NuGet makes can be committed to source control and the changes that NuGet makes can be x-copy deployed. This allows you to install a set of packages and commit the changes so that when your co-worker gets latest, her development environment is in the same state as yours. This is why NuGet packages do not install assemblies into the GAC as that would make it difficult to meet these two goals. NuGet doesn’t touch anything outside of your solution folder. It doesn’t install programs onto your computer. It doesn’t install extensions into Visual studio. It leaves those tasks to other package managers such as the Visual Studio Extension manager and the Web Platform Installer.
  2. Works against a well known central feed.As part of this project, we plan to host a central feed that contains (or points to) NuGet packages. Package authors will be able to create an account and start adding packages to the feed. The NuGet client tools will know about this feed by default.
  3. No central approval process for adding packages. When you upload a package to the NuGet Package Gallery (which doesn’t exist yet), you won’t have to wait around for days or weeks waiting for someone to review it and approve it. Instead, we’ll rely on the community to moderate and police itself when it comes to the feed. This is in the spirit of how CodePlex.com and RubyGems.org work.
  4. Anyone can host a feed. While we will host a central feed, we wanted to make sure that anyone who wants to can also host a feed. I would imagine that some companies might want to host an internal feed of approved open source libraries, for example. Or you may want to host a feed containing your curated list of the best open source libraries. Who knows! The important part is that the NuGet tools are not hard-coded to a single feed but support pointing them to multiple feeds.
  5. Command Line and GUI based user interfaces. It was important to us to support the productivity of a command line based console interface. Thus NuGet ships with the PowerShell based Package Manager Console which I believe will appeal to power users. Likewise, NuGet also includes an easy to use GUI dialog for adding packages.

NuGet’s Primary Goal

In my mind, the primary goal of NuGet is to help foster a vibrant open source community on the .NET platform by providing a means for .NET developers to easily share and make use of open source libraries.

As an open source developer myself, this goal is something that is near and dear to my heart. It also reflects the evolution of open source in DevDiv (the division I work in) as this is a product that will ship with other Microsoft products, but also accepts contributions. Given the primary goal that I stated, it only makes sense that NuGet itself would be released as a truly open source product.

There’s one feature in particular I want to call out that’s particularly helpful to me as an open source developer. I run an open source blog engine called Subtext that makes use of around ten to fifteen other open source libraries. Before every release, I go through the painful process of looking at each of these libraries looking for new updates and incorporating them into our codebase.

With NuGet, this is one simple command: List-Package –updates. The dialog also displays which packages have updates available. Nice!

And keep in mind, while the focus is on open source, NuGet works just fine with any kind of package. So you can create a network share at work, put all your internal packages in there, and tell your co-workers to point NuGet to that directory. No need to set up a NuGet server.

Get Involved!

So in the fashion of all true open source projects, this is the part where I beg for your help. ;)

It is still early in the development cycle for NuGet. For example, the Add Package Dialog is really just a prototype intended to be rewritten from scratch. We kept it in the codebase so people can try out the user interface workflow and provide feedback.

We have yet to release our first official preview (though it’s coming soon). What we have today is closer in spirit to a nightly build (we’re working on getting a Continuous Integration (CI) server in place).

So go over to the NuGet website on CodePlex and check out our guide to contributing to NuGet. I’ve been working hard to try and get documentation in place, but I could sure use some help.

With your help, I hope that NuGet becomes a wildly successful example of how building products in collaboration with the open source community benefits our business and the community.

Tags: NuGet, Package Manager, Open Source

Found a typo or error? Suggest an edit! If accepted, your contribution is listed automatically here.

Comments

avatar

27 responses

  1. Avatar for Rob White
    Rob White October 5th, 2010

    The thing that maybe I'm just not seeing is; where are the actual assembly files put, do they go into the GAC, do they end up in a folder related to your project somehow? Essentially what I'm wondering is, how will this work with a build server? If I add a package and write some code against that package, when I check my code in, will the build server need to fetch those packages as well? I guess the same question applies to deployment senarios.

  2. Avatar for Ian Cooper
    Ian Cooper October 5th, 2010

    You may also want to use OpenWrap as an alternative to using NuPack: serialseb.blogspot.com/...

  3. Avatar for Will Shaver
    Will Shaver October 5th, 2010

    Congrats on the NuPack and MVC Releases. In your "guiding principles" I found "works against your source code" to be confusing. You probably want "works with your source code" or "on" or any number of other words. I first read that as "works antagonistically with your source code" ...
    Then again, I never was too bright.

  4. Avatar for Philip
    Philip October 5th, 2010

    It would be quite nice if this were not "included" with MVC3 at release - It certainly has lots of usage outside it, and I hate having to install something to get the benefits of an unrelated feature.

  5. Avatar for haacked
    haacked October 5th, 2010

    @Rob, it puts the assemblies in a subfolder of the "packages" folder which is place inside your solution folder. So if you add your entire solution folder to source control, you're all set.
    @Will Thanks! I corrected it.
    @Philip you don't have to install MVC 3 to get it. Just grab the VSIX from http://nupack.codeplex.com/

  6. Avatar for Jared Roberts
    Jared Roberts October 5th, 2010

    Is there something I am doing wrong?
    PM> List-Package
    Exception calling "GetPackageManager" with "1" argument(s): "The path is not of a legal form."
    At D:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\Extensions\CodePlex Foundation\NuPack Tools\0.1\Scripts\nupack
    .ps1:524 char:80
    + $packageManager = [NuPack.VisualStudio.VsPackageManager]::GetPackageManager <<<< ([object]$dte)
    + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : DotNetMethodException

  7. Avatar for Jared Roberts
    Jared Roberts October 5th, 2010

    nevermind, it appears you have to be in a project or solution. I was in a website.

  8. Avatar for Chris
    Chris October 5th, 2010

    Getting this error when I open up the Package Manager Window:

    The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\WINDOWS\system32\WindowsPowerShell\v1.0\types.ps1xml(2943) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: Cannot convert the "Microsoft.PowerShell.Commands.SecurityDescriptorCommandsBase" value of type "System.String" to type "System.Type".
    The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\WINDOWS\system32\WindowsPowerShell\v1.0\types.ps1xml(2950) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: Cannot convert the "Microsoft.PowerShell.Commands.SecurityDescriptorCommandsBase" value of type "System.String" to type "System.Type".
    The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\WINDOWS\system32\WindowsPowerShell\v1.0\types.ps1xml(2957) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: Cannot convert the "Microsoft.PowerShell.Commands.SecurityDescriptorCommandsBase" value of type "System.String" to type "System.Type".
    The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\WINDOWS\system32\WindowsPowerShell\v1.0\types.ps1xml(2964) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: Cannot convert the "Microsoft.PowerShell.Commands.SecurityDescriptorCommandsBase" value of type "System.String" to type "System.Type".
    The following error occurred while loading the extended type data file: Microsoft.PowerShell.Core, C:\WINDOWS\system32\WindowsPowerShell\v1.0\types.ps1xml(2971) : Error in type "System.Security.AccessControl.ObjectSecurity": Exception: Cannot convert the "Microsoft.PowerShell.Commands.SecurityDescriptorCommandsBase" value of type "System.String" to type "System.Type".
    System.Management.Automation.ActionPreferenceStopException: Command execution stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: Unable to find type [NuPackConsole.Host.PowerShell.Implementation.PSTypeWrapper]: make sure that the assembly containing this type is loaded.
    at System.Management.Automation.Runspaces.PipelineBase.Invoke(IEnumerable input)
    at System.Management.Automation.Runspaces.Pipeline.Invoke()
    at NuPackConsole.Host.PowerShell.Implementation.PowerShellHost.Invoke(String command, Object input, Boolean outputResults)
    at NuPackConsole.Host.PowerShell.Implementation.PowerShellHost.LoadStartupScripts()
    at NuPackConsole.Host.PowerShell.Implementation.PowerShellHost.Initialize()
    at NuPackConsole.Host.PowerShell.Implementation.PowerShellHostProvider.<>c__DisplayClass2.<CreateHost>b__1(Object sender, EventArgs e)
    at NuPackConsole.CommonExtensionMethods.Raise(EventHandler ev, Object sender, EventArgs e)
    at NuPackConsole.Implementation.Console.ConsoleDispatcher.Start()
    at NuPackConsole.Implementation.PowerConsoleToolWindow.MoveFocus(FrameworkElement consolePane)

  9. Avatar for Paul Cox
    Paul Cox October 5th, 2010

    Does NuPack have any mechanisms for getting the bleeding edge version of a product, e.g. NHibernate 3?

  10. Avatar for Chris
    Chris October 5th, 2010

    Was able to add a package after closing and restarting VS2010, but I don't see any changes to the web.config under httpModules section.

  11. Avatar for Alec Whittington
    Alec Whittington October 6th, 2010

    Congrats on the NuPack release as well as the MVC 3 Beta release.
    NuPack is long over due for the .NET community.

  12. Avatar for Jonas
    Jonas October 6th, 2010

    Phil, why powershell? I would love for it to have a user interface using powershell behind the scenes and have the ability to use either.

  13. Avatar for Gregg
    Gregg October 6th, 2010

    @Jonas: Installing the extension also adds an "Add Package Reference..." option in VS2010. (Phil mentions it in passing above but doesn't really explain much about it. It's there, though.) You can use either the PowerShell approach or the GUI-style depending on your mood.

  14. Avatar for Keith J. Farmer
    Keith J. Farmer October 6th, 2010

    Excellent!
    Need to add NuPack to the VS Extension Manager feed. :)
    By any chance does NuPack currently add support for adding packages to the machine itself, outside the context of VS or the like, or could it be extended to do so? I'm thinking akin to WebPI or Windows Update.
    Does it have update- or rename-package facilities? Perhaps optionally alasing a package (eg, to deal with new Magic Unicorn drops that require some work to transition)?

  15. Avatar for Eric Falsken
    Eric Falsken October 6th, 2010

    How do I contribute a package to the library?

  16. Avatar for haacked
    haacked October 6th, 2010

    @Chris Upgrade your reflector to 6.5. See the FAQ and list of Known Issues.
    @Paul if someone adds a package for it, sure. We don't yet have a way to distinguish between stable and pre-release yet though.
    @Jonas PowerShell is a thin wrapper over our core API. We *also* have a GUI. Check out this 1.5 minute intro video!
    @Keith Yes, we plan to add it to the VS Extension Manager. No plans to support adding packages outside of a VS solution.
    @Eric the current feed is a temporary measure. Read the FAQ and it'll walk you through how to get a package there.

  17. Avatar for John Moshakis
    John Moshakis October 6th, 2010

    Is the command line interface tied to specific languages ?
    Its just that the vsix install doesn't seem to recognize the visual studio shell as a valid application.

  18. Avatar for Chris
    Chris October 6th, 2010

    Does it put the packages folder in the same directory as the sln file regardless of where that is, or next to the project files?
    What if I don't want them in 'packagee'? Can you alter the default location, like a folder directory above the solution directory (think a libs folder shared by many related project directories.

  19. Avatar for Adam
    Adam October 6th, 2010

    it would be great if we could configure where the packages are stored. so change the 'packages' folder to say 'libs' or whatever our organisation prefers. otherwise, great step forward guys!

  20. Avatar for Christopher Painter
    Christopher Painter October 6th, 2010

    Here's my two concerns:
    1) How does it handle the build environment? Does this assume you'll check the package files into source control so the build will pull it down as part of the workspace? Our current build proccesses avoid this intentionally.
    2) While it's great to get some cool widget into the hands of a developer, I'm concerned it's an abstraction that many people will use to turn off their brain when it comes to dependency / integration analysis. Just issue the get package command, rebuild the solution and publish. Easy, right?
    Still, if those concerns aren't a worry, it does seem like a really slick tool.

  21. Avatar for Matt Mills
    Matt Mills October 7th, 2010

    Does the feed allow contributors to tag upgrades as breaking or otherwise incompatible with previous versions?

  22. Avatar for Robert Standefer
    Robert Standefer October 7th, 2010

    In all the demos and videos, the person is installing elmah, but elmah isn't listed as an available package when I run NuPack. It also doesn't install from the command line (I get an error that says elmah can't be found).
    What gives?

  23. Avatar for Josh
    Josh October 7th, 2010

    Anyone know where to get Ninject MVC2 using nupack?

  24. Avatar for Steve
    Steve October 9th, 2010

    I grabbed MvcTurbine and Windsor - and it was fine, except MvcTurbine uses a prior version of the Windsor included.
    Anything to be done for this - because these types of mismatches are the real problem with OSS imo - not the delivery system (although a delivery system is nice to have).

  25. Avatar for Esteban
    Esteban October 11th, 2010

    @Robert Same here. I installed this just for elmah and it's not even in the package list.
    Do I need to download a list from somewhere else?

  26. Avatar for George Birbilis
    George Birbilis November 8th, 2010

    Nice images at 2nd part of tell the story of NuGet power in a few words:
    weblogs.asp.net/...

  27. Avatar for Stoyan
    Stoyan December 27th, 2010

    I wasn't able to install NuPack.Server on IIS 7 on a Windows 2008 box - web deployment failed w/ various errors, I tried everything and the kitchen sink and couldn't make this work. Is there *anyone* who was able to deploy the server to provide a local repository at his company? TIA, Stoyan