Wednesday, October 17, 2012

Add the Visual Studio Command Prompt to VS2012

Several times this week, I wanted to launch a Windows command prompt (not the VS Command Window which is different) while in Visual Studio 2012. More specifically, I wanted to open the command prompt in the directory of the item I had selected in Solution Explorer. I swear I could do that in VS2010 but I can’t find that in VS2012.

I gave up and did a two step dance:

  1. Right-click selected folder | “Open Folder in File Explorer” [alternatively: “Open Containing Folder”]
  2. Ctrl-Shift-right-click | “Open command window here”

That works for most purposes although I don’t benefit from the VS-specific environment variables.

Then I stumbled across an old blog post by V K Sumesh (2008) that describes how to add the Visual Studio Command Prompt (VSCP) to the tools menu. That’s worth a read for background. I’ve updated the steps here for VS 2012 and to suit my preferences.

Add VSCP to the Tools menu

  1. Tools | External Tools …
  2. Click [Add]
  3. Title: Command Prompt
  4. Command: C:\Windows\System32\cmd.exe
  5. Arguments: "%programfiles%\Microsoft Visual Studio 11.0\Common7\Tools\vsvars32.bat"
  6. Initial directory: $(ItemDir)
  7. Click [Move Up] to position the command (I put mine at the top)

In step #5 I’ve specified vsvars32.bat, a batch file that supplements the Windows environment variables with environment variables for the .NET framework tools.

In step #6 I picked the “Item directory” because that’s my preference but the dialog offers other choices which may suit you better.

Here’s what it looks like before I click [OK]

VSCP

Use it

  1. In Solution Explorer select the folder or item where you want the command window to open
  2. Tools | Command Prompt

Hope that helps. Let me know if there’s a better way.

Update

The “Open command prompt” feature that I remembered from VS2010 came by way of the Microsoft “PowerCommands for VS 2010” extension.

Apparently the 2010 extension works for VS2012 as well. Take note: there are a ton of features in that extension, many of them already in VS2012. I was worried about redundancy and bloating my context menu with ever more rarely used options. But it seems well-behaved and you can disable features you don’t want via Tools | Options | PowerCommands. It’s a worthy alternative to the technique I described above.

2 comments:

Csaba Toth said...

A simple solution if you have Visual Studio 2012 Professional or above: "Productivity Power Tools" extension. After installation it has this feature too:
"Open Command Prompt
Opens a Visual Studio command prompt pointing to the physical path of a selected item. It can be executed from four different places: solution, project, folder and project item nodes respectively."
http://visualstudiogallery.msdn.microsoft.com/3a96a4dc-ba9c-4589-92c5-640e07332afd

Csaba Toth said...

I forgot to add: the extension is free. You just need to have VS 2012 Prof or above.