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:
- Right-click selected folder | “Open Folder in File Explorer” [alternatively: “Open Containing Folder”]
- 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
- Tools | External Tools …
- Click [Add]
- Title: Command Prompt
- Command: C:\Windows\System32\cmd.exe
- Arguments: "%programfiles%\Microsoft Visual Studio 11.0\Common7\Tools\vsvars32.bat"
- Initial directory: $(ItemDir)
- 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]
Use it
- In Solution Explorer select the folder or item where you want the command window to open
- 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.