两种方法:
方法1:
//output window
OutputWindow ow = (this.dte as DTE2).ToolWindows.OutputWindow;
OutputWindowPane owP;
// Add a new pane to the Output window.
owP = ow.OutputWindowPanes.Add("A New Pane");
// Add a line of text to the new pane.
owP.OutputString("hello my output window");
方法2:
IVsOutputWindow outputWindow = GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;
// Guid guildGeneral = Microsoft.VisualStudio.VSConstants.OutputWindowPaneGuid.GeneralPane_guid;
Guid guildGeneral = VSConstants.OutputWindowPaneGuid.BuildOutputPane_guid;
int hr = output.CreatePane(guildGeneral, "Build1", 1, 0);
hr = output.CreatePane(guildGeneral, "Build2", 1, 0);
hr = output.CreatePane(guildGeneral, "Build3", 1, 0);
hr = output.CreatePane(guildGeneral, "Build4", 1, 0);
IVsOutputWindowPane pane;
int hr = outputWindow.GetPane(ref guildGeneral, out pane);
pane.Activate();
pane.OutputString("Hello world");
Guid customGuid = new Guid("0F44E2D1-F5FA-4d2d-AB30-22BE8ECD9789");
string customTitle = "Custom Window Title";
outputWindow.CreatePane(ref customGuid, customTitle, 1, 1);
IVsOutputWindowPane customPane;
outputWindow.GetPane(ref customGuid, out customPane);
customPane.OutputString("Hello, Custom World!");
customPane.Activate(); // Brings this pane into view
方法1更优雅。