Opening a command prompt for your project


Sometimes while working with a VS.Net project, you need to run a command line tool, either on the sources or output of the project.  VS provides an easy way to add a menu item that will open a command prompt in the target directory of your application, or in the source folder.


In order to enable this, first go to the Tools menu, and choose External Tools.  In the add dialog box, create a new item, and give it a name such as Source Shell.  The command should be cmd.exe.  For initial directory, you can pick one of:



  • $(ProjectDir) – source code for the current project

  • $(SolutionDir) – root directory of the current solution

  • $(TargetDir) – build location of the current project.  This will adjust for different configurations, so it will open a shell in bin\Debug for debug builds, and bin\Release for release builds.

In my copy of VS I have a menu option for Source Shell, opening in $(ProjectDir), and one for Build Shell, opening in $(TargetDir).  I also have a quick script that I run that sets up various environment variables, network drive maps, and drive substitutions, in order for me to have a useful dev command window.  I get this script to run by adding


/k SetDevEnv.cmd


To the arugments line.

Comments (4)

  1. Puchi says:

    That is pretty interesting. To take it a step further, it would be great if you could get the command window inside the editor. There is an option for that "use output window" but when I execute the tool, the command window comes in read-only mode in the editor and I cannot do much with it. Do you know of any other way in which I can type in commands in the window after getting it in the VS Editor.

    Thanks a lot

  2. Shawn says:

    Hi Puchi

    What you’re looking for is functionality similar to WinDbg’s .shell command. Unfortunately there’s nothing like that in Visual Studio (at least as far as I know, if anyone has a trick to show how this is done, feel free to post it here). Like you pointed out, adding the "use output window" option only shows the output of the command prompt in the output window, and doesn’t let you interact with the prompt. From the VS command window you could run Tools.Shell cmd.exe, but that too will spawn an external command shell.

    -Shawn

  3. It looks like I won’t have to make my own command prompt plugin for Visual Studio after all – this feature is included in Visual Studio 2005. Sweet! :) (In the meantime, as a quick substitute you can create External…

  4. Ethor says:

    I need to pass text that I have created in a .txt file to the cmd line and run the command, while being hidden from the front end of the project. Any suggestions of how to go about this