Logo
HOWTO: Get an OutputWindowPane to output some string from a Visual Studio add-in or macro

Author: Carlos J. Quintero (Microsoft MVP) Applies to: Microsoft Visual Studio .NET 2002
Date: August 2008   Microsoft Visual Studio .NET 2003
Updated: March 2013   Microsoft Visual Studio 2005
      Microsoft Visual Studio 2008
      Microsoft Visual Studio 2010
      Microsoft Visual Studio 2012
Introduction

Visual Studio provides an Output window ("View", "Other Windows", "Output" menu) to show messages, debug information, etc. That window provides several panes that can be selected through a combobox, such as "Source Control", "Build", "Debug", etc.

The automation model (EnvDTE) provides the EnvDTE.OutputWindow, EnvDTE.OutputWindowPanes and EnvDTE.OutputWindowPane classes. When you try to get a specific OutputWindowPane through OutputWindow.OutputWindowPanes.Item(name), it can fail in international versions of Visual Studio since names are localized (while in English an output window pane is "Build", in Spanish is "Generar").

More Information

To get the an instance of EnvDTE.OutputWindow see the following article:

HOWTO: Get the programmable inner object of a toolwindow

Once you have it, you shouldn't retrieve an OutputWindowPane by name since it can be localized in international versions of Visual Studio. Instead, you can use the Guid property of each output pane that identifies uniquely each pane. Microsoft provides some known Guids in the following link ("Output Pane" section):

IDE Guids

If the Guid that you are looking for is not in that list, you can iterate the output panes querying the name and Guid of each pane until you locate the Guid of the pane that you are interested in.

The following macro gets the Build output pane and writes a string to it:

    Sub WriteToBuildOutputPane()

        Const BUILD_OUTPUT_PANE_GUID As String = "{1BD8A850-02D1-11D1-BEE7-00A0C913D1F8}"

        Dim objOutputToolWindow As Window
        Dim objOutputWindow As OutputWindow
        Dim objOutputWindowPane As OutputWindowPane
        Dim objBuildOutputWindowPane As OutputWindowPane

        objOutputToolWindow = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
        objOutputWindow = DirectCast(objOutputToolWindow.Object, OutputWindow)

        For Each objOutputWindowPane In objOutputWindow.OutputWindowPanes
            If objOutputWindowPane.Guid.ToUpper = BUILD_OUTPUT_PANE_GUID Then
                objBuildOutputWindowPane = objOutputWindowPane
                Exit For
            End If
        Next

        If Not (objBuildOutputWindowPane Is Nothing) Then
            objBuildOutputWindowPane.OutputString("My name is " & objBuildOutputWindowPane.Name & ", which can be localized!")
        End If

    End Sub


Go to the 'Visual Studio Extensibility (VSX)' web site for more articles like this (Articles section)


Top