Write To Visual Studio’s Output Window

If you have developed a Visual Studio Extension, you might want to output messages to Visual Studio’s Output window. Here’s how to do it:

using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;

namespace MunirHusseini.Demos
{
    public class VsOutput
    {
        public static void Output(string msg)
        {
            // Get the output window
            var outputWindow = Package.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;

            // Ensure that the desired pane is visible
            var paneGuid = Microsoft.VisualStudio.VSConstants.OutputWindowPaneGuid.GeneralPane_guid;
            IVsOutputWindowPane pane;
            outputWindow.CreatePane(paneGuid, "General", 1, 0);
            outputWindow.GetPane(paneGuid, out pane);

            // Output the message
            pane.OutputString(msg);
        }
    }
}

Of course, you could output to other panels than just “General”. To do that, just change the value of the variable paneGuid. Possible values are:

BuildOutputPane_guid The build output pane inside the output window.
DebugPane_guid The debug pane inside the output window.
GeneralPane_guid The general output pane inside the output window.
SortedBuildOutputPane_guid The sorted build output pane inside the output window.
StoreValidationPane_guid The store validation pane inside the output window.

For a visual demonstration, please watch this video.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s