NuGet Support for Visual Studio 2008

浏览: 127 发布日期: 2016-08-18 分类: visual-studio

Well, not really. A better title would be "How to Cobble Together NuGet Support for Visual Studio 2008 with External Tools and a Prayer." The point is, there are lots of folks using Visual Studio 2008 who would like NuGet support. I'm exploring this area and there's a half-dozen ways to make it happen, some difficult and some less so. The idea would be to enable some things with minimal effort. It'll be interesting to see if there are folks in the community who think this is important enough to actually make it happen. Of course, the easiest thing is to just use 2010 as it sill supports .NET 2.0, 3.0, 3.5, and 4, but not everyone can upgrade.

Someone could:

  • Backport the existing NuGet Package References dialog to 2008 using that version's native extensions (not VSiX)

  • Create MEF (Managed Extensibility Framework) plugins for the nuget.exe command-line to update the references in a vbproj or csproj

  • Use PowerShell scripts and batch files to get the most basic stuff working (get a package and update references.)

    • Maybe write a shim to get DTE automation working...

But that's coulds and maybes. Let's talk about the MacGyver solution.

Launch Visual Studio 2008 and go to Tools | External Tools.

Make a new Tool with these values:

  • Title: NuGet Install

  • Command (I'm assuming this is in the PATH): nuget.exe

  • Arguments: install -excludeversion -outputDirectory .\Packages

  • Initial directory: $(SolutionDir)

  • Use Output window: Checked

  • Prompt for arguments: Checked
    Next, right click in the Tookbar area and create a new Toolbar called NuGet. From Commands, drag in the correct Tools | External Tool button. Right click it and design to taste:

Now, when you click Install Package, you should change to whatever the you want is, and click OK. Note the output in the console window below.

At this point, because we are only integrating the command line too, you don't get the references added automatically. And where's the packages? Well, they are here, one directory up under Packages. It's still up to you to add the reference yourself and make sure it's the appropriate one (I refer you again to the wish list above.)

If you are feeling extra fancy, you can even add a few macros and links in your Toolbar to send you to the NuGet site for searching. Here's a Visual Studio 2008 macro that launches your default web browser and takes you to

Public Module NuGet
    Sub LaunchNuGetSite()
        Dim p As New System.Diagnostics.Process()
    End Sub
End Module

Then make toolbar buttons for those extra buttons, like this one for going to the NuGet site and searching:

Thoughts, Dear Reader?

from hanselman