Home DotNet How to Write to Output Windows in Visual Studio
How to Write to Output Windows in Visual Studio

We normally want to write message to the Output Window so that we could do some testing. Well you can write to the Output Windows easily using one of a few methods below:

Solution 1:

Add the System.Diagnostics namespace to the top of the code page. Then you can use Trace.WriteLine to write message to the output window.

private void SetLibraryToFunctionalLocation(TreeListNode node)

{

        foreach (TreeListNode childNode in node.Nodes)

        {

            Trace.WriteLine(childNode.GetValue("EntityNumber").ToString());

 

            if (childNode.Nodes.Count > 0)

            {

                SetLibraryToFunctionalLocation(childNode);

            }

        }

}

 

output-window

 

Solution 2:

 

To write to the general window:

 

IVsOutputWindow outWindow = Package.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;

 

Guid generalPaneGuid = VSConstants.GUID_OutWindowGeneralPane; // You can also use the GUID_OutWindowDebugPane window.

IVsOutputWindowPane generalPane;

outWindow.GetPane(ref generalPaneGuid, out generalPane);

 

generalPane.OutputString("Hello World!");

generalPane.Activate(); // Show the output window pane


To write to the custom window:

IVsOutputWindow outWindow = Package.GetGlobalService( typeof( SVsOutputWindow ) ) as IVsOutputWindow; 

// Use e.g. Tools -> Create GUID to make a stable, but unique GUID for your pane.

Guid customGuid = new Guid("0F44E2D1-F5FA-4d2d-AB30-22BE8ECD9789");

string customTitle = "Custom Window Title";

outWindow.CreatePane( ref customGuid, customTitle, 1, 1 );

 

IVsOutputWindowPane customPane;

outWindow.GetPane( ref customGuid, out customPane);

 

customPane.OutputString( "Hello, Custom World!" );

customPane.Activate(); // Show the output window pane



Comments (0)
Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:D:angry::angry-red::evil::idea::love::x:no-comments::ooo::pirate::?::(
:sleep::););)):0
Security
Please input the anti-spam code that you can read in the image.

"