How to: Control the Command Window
Visual Studio add-ins are deprecated in Visual Studio 2013. You should upgrade your add-ins to VSPackage extensions. For more information about upgrading, see FAQ: Converting Add-ins to VSPackage Extensions.
The CommandWindow object represents the Command window in the Visual Studio automation model. You can use the CommandWindow object to:
Insert a command into the Command window and, optionally, execute it by using the SendInput method.
Insert informational text into the Command window by using the OutputString method.
Clear all text from the Command window by using the Clear method.
In addition to controlling the contents of the Command window, you can also control its characteristics, such as width and height. For more information, see How to: Change Window Characteristics.
Note
The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. These procedures were developed with the General Development Settings active. To change your settings, choose Import and ExportSettings on the Tools menu. For more information, see Customizing Development Settings in Visual Studio.
Example
This example demonstrates how to reference and use the various members of the Command window automation model. For more information about how to run the example, see How to: Compile and Run the Automation Object Model Code Examples.
Public Sub OnConnection(ByVal application As Object, ByVal _
connectMode As ext_ConnectMode, ByVal addInInst As Object, _
ByRef custom As Array) Implements IDTExtensibility2.OnConnection
_applicationObject = CType(application, DTE2)
_addInInstance = CType(addInInst, AddIn)
' Pass the applicationObject member variable to the code example.
CommandWinExample(_applicationObject)
End Sub
Sub CommandWinExample(ByVal dte As DTE2)
Try
' Get a reference to the Command window.
Dim CW As CommandWindow = dte.ToolWindows.CommandWindow
' Insert informative text into the Command window.
CW.OutputString("This takes you to the Microsoft Web site.")
' Add a command to the Command window and execute it.
CW.SendInput("nav https://www.microsoft.com", True)
' Clear the contents of the Command window.
MsgBox("Clearing the Command window...")
CW.Clear()
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
public void OnConnection(object application, ext_ConnectMode
connectMode, object addInInst, ref Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
// Pass the applicationObject member variable to the code example.
CommandWinExample(_applicationObject);
}
public void CommandWinExample(DTE2 dte)
{
try
{
// Get a reference to the Command window.
CommandWindow CW = dte.ToolWindows.CommandWindow;
// Insert informative text into the Command window.
CW.OutputString("This takes you to the Microsoft Web site.");
// Add a command to the Command window and execute it.
CW.SendInput("nav https://www.microsoft.com", true);
// Clear the contents of the Command window.
System.Windows.Forms.MessageBox.Show(
"Clearing the Command window...");
CW.Clear();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
}
}
See Also
Tasks
How to: Change Window Characteristics
Walkthrough: Creating a Wizard