I have moved my active blog over to tumblr. I've maintained this blog for reference but will be posting to http://www.robustsoftware.co.uk instead. I've pointed my Feedburner feed to tumblr so if you're subscribed already you should already have switched with me.

Opening a Command Prompt for the solution in Visual Studio

Something I’ve found myself needing to do more recently is open a command prompt at the root directory of my solution. Often this is to run a rake task or something like that.

The way I used to do this was rather long winded, but now I’ve got it down to a single key combination and I’ll explain here how you can do the same.

Firstly, open up the external tools dialog in Visual Studio:

 externaltools_menu

Then add a new tool:

externaltools_add

This will give you a prompt to type the details of the new tool into:

externaltools_adddialog

Then fill in the details of the new tool. We want to point this at cmd.exe which is usually located in your System32 directory. You also want to set the initial directory to the solution directory:

externaltools_solution

I have then moved the tool up the list just because I like it being higher. The position of the tool in the list only makes a difference when setting up a keyboard shortcut as I will explain in a minute:

externaltools_moveup

Once you’ve filled in all the details and moved the tool to the position you want it in just click Ok. You will now see that the tool you just created appears in the external tools section of the tools menu:

externaltool_in_menu

Now we can set up a keyboard shortcut for the new tool. Firstly, open the options dialog:

tools_options

Then go to the keyboard section:

options_keyboard

Then type in the command name “Tools.ExternalCommandX” where X is the number your tool appears in the list. Mine is second so I type “2”:

tools_keyboard_externalcommand2

Then assign a key combination to this command. I chose Ctrl+Shift+Alt+C:

tools_keyboard_assign

Then click ok and you will now be able to open a command prompt at the root of the current solution with your key combination.

This principle can be extended to call any program, you may have noticed I use it to call the default rake task for my solution.