| 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: 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); } } }
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
// 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
|
