Basics of using the Command Window in Visual Studio 2010

Here at Microsoft, developers LOVE the Visual Studio Integrated Development Environment (IDE) because it saves developers time by being well featured and powerful.  After working at Microsoft for a while I noticed that the Windows core developers use a feature of Visual Studio, the Command Window, in their day-to-day work as an essential part of development. Being an ex-Vim junkie, I drooled while watching a well-in-tune developer zip through a debugging session and decided I needed to figure this cool trick out. In this post, I'll give you a taste of what you can do from the command window so that you too can also take advantage of this powerful feature.

To put it simply, the Command Window lets you use a command line interface (CLI) to control Visual Studio.  You can use the Command Window for editing, testing, building, and debugging; but, for me, it's a good way to avoid unnecessary mousing while using VS.  Seasoned users of the Command Window will attest that it saves them oodles of time by letting them speedily perform complex steps in Visual Studio.

Invoking the Command Window

To bring up the command window, press CTRL+ALT+A. When you do this, the bottom of the IDE will change to have the command window tab selected.  The following screenshot shows my instance of Visual Studio with the command window open.

The Command Window prompt looks very similar to the DOS prompt,  with a > shaped cursor.  Typing into the Command Window will invoke commands and will also pop up Intellisense.  The following screenshot shows what Intellisense begins hinting at when I type in Build. (...).

By using the arrow keys, you can pick a command from the list as it appears.  Alternately, you can type and Intellisense will autofill / correct for you.  That said, as an alternative to Ctrl+Alt+B or Ctrl+F7, you can type in Build.Compile to compile your program.  Then you can type Debug.Start to begin debugging.

In my application, I have inserted a deliberate bug, divide by zero for those who are curious 🙂 When my program encounters this bug, it crashes and I get the "something is wrong... break/continue" dialog.  This is a simulation of the real scenario when you encounter bugs in code.  If you are running a program, it crashes, and you have the command window open, the command window will receive focus and you can do some interesting things in terms of debugging.

Debugging with the Command Window

There are a few command aliases that are extremely handy in the debug window for tracking variables:

? - tells you the value of a variable

?? - pulls a variable into a watch window

locals - shows the locals window (CTRL+ALT+A to flip back to the command window)

autos - shows the autos window

Also of interest, there's are command aliases for jumping to lines in code and setting break points.

GotoLn - Set the cursor to a specific line in the program.

bp - Set a breakpoint on the currentline

In my example, I can pull up the values for the variables that I have creatively named i and j by typing in:

>? i

>? j

The output from these commands is in the following screenshot:

The command window shows that i is 10 and j is 0, since j is the denominator of a division operation, and the variable is set to 0, I know that I need to figure out why j is zero and I can fix the bug from there.

Pro Tips

Similar to the Command Window, the Immediate Window lets you test code without having to build and run it.  You can also use the immediate window as a command Window by prefixing a command with the > character.

To clear out the contents of the Command Window, use the command cls.

To list all aliases, type in alias without a parameter.

To delete an alias, type in alias aliasname /delete

See Also


Comments (4)

  1. Felipe Volpatto says:

    Nice, I liked!

  2. dunno says:

    how to open the command prompt window when running debugging? I want to add in a console.writeline statement inside the coding to do debugging in like check if the program run until that part of the coding. How do i actually do that? because i tried debugging but the command prompt window did not come out. What function must i press in order for the command prompt window to appear?

  3. Chris says:

    My default install of 2010 shows the 'Immediate Window' anytime I debug. Doesn't this provide similar functionality as the 'Command Window' when you're not running any code?

  4. Greg says:

    using control-alt-A does not bring up the command window.  i need to use the mouse and go to view menu.  ???

Skip to main content