This article applies to Visual Studio 2015. If you're looking for Visual Studio 2017 documentation, use the version selector at the top left. We recommend upgrading to Visual Studio 2017. Download it here.
The Command window is used to execute commands or aliases directly in the Visual Studio integrated development environment (IDE). You can execute both menu commands and commands that do not appear on any menu. To display the Command window, choose Other Windows from the View menu, and select Command Window.
Displaying the Values of Variables
To check the value of a variable
varA, use the Print Command:
The question mark (?) is an alias for
Debug.Print, so this command can also be written:
Both versions of this command will return the value of the variable
The greater than symbol (
>) appears at the left edge of the Command window as a prompt for new lines. Use the UP ARROW and DOWN ARROW keys to scroll through previously issued commands.
|Evaluate an expression.||Preface the expression with a question mark (
|Switch to an Immediate window.||Enter
|Switch back to the Command window from an Immediate window.||Enter
The following shortcuts help you navigate while in Command mode.
|Cycle through the list of previously entered commands.||Input line||UP ARROW & DOWN ARROW|
|Scroll up the window.||Command window contents||CTRL+UP ARROW|
|Scroll down the window.||Command window contents||DOWN ARROW or CTRL+DOWN ARROW|
You can copy all or part of a previous command to the input line by scrolling to it, highlighting all or part of it, and then pressing ENTER.
When you click on any previous line in the Command window, you shift automatically into Mark mode. This allows you to select, edit, and copy the text of previous commands as you would in any text editor, and paste them into the current line.
The Equals (=) Sign
The window used to enter the
EvaluateStatement command determines whether an equals sign (=) is interpreted as a comparison operator or as an assignment operator.
In the Command window, an equals sign (=) is interpreted as a comparison operator. You cannot use assignment operators in the Command window. So, for example, if the values of variables
varB are different, then the command
will return a value of
In the Immediate window, by contrast, an equals sign (=) is interpreted as an assignment operator. So, for example, the command
will assign to variable
varA the value of variable
Parameters, Switches, and Values
Some Visual Studio commands have required and optional arguments, switches and values. Certain rules apply when dealing with such commands. The following is an example of a rich command to clarify the terminology.
Edit.ReplaceInFiles /case /pattern:regex var[1-3]+ oldpar
In this example,
Edit.ReplaceInFilesis the command
/pattern:regexare switches (prefaced with the slash [/] character)
regexis the value of the
/caseswitch has no value
Any command, parameter, switch, or value that contains spaces must have double quotation marks on either side.
The position of switches and parameters can be interchanged freely on the command line with the exception of the Shell command, which requires its switches and parameters in a specific order.
Nearly every switch supported by a command has two forms: a short (one character) form and a long form. Multiple short-form switches can be combined into a group. For example,
/p /g /mcan be expressed alternately as
If short-form switches are combined into a group and given a value, that value applies to every switch. For example,
/p:123 /g:123 /m:123. An error occurs if any of the switches in the group does not accept a value.
A caret (^) character in a command line means that the character immediately following it is interpreted literally, rather than as a control character. This can be used to embed straight quotation marks ("), spaces, leading slashes, carets, or any other literal characters in a parameter or switch value, with the exception of switch names. For example,
>Edit.Find ^^t /regex
A caret functions the same whether it is inside or outside quotation marks. If a caret is the last character on the line, it is ignored. The example shown here demonstrates how to search for the pattern “^t”.
Use Quotes for Path Names with Spaces
If, for example, you want to open a file that has a path containing spaces, you must put double quotes around the path or path segment that contains spaces: C:\"Program Files" or "C:\Program Files".