Writing to output pane of VS2013 in C# VsPackage fails
I'm trying to write some string data to the output pane of Visual studio 2013 as part of a C# VSPackage. I've copied some tutorial code (http://msdn.microsoft.com/en-us/library/cc138529.aspx) that is meant to get the pane so you can write to it but when I run the experimental vs build in debug mode with my vspackage and trigger the button callback that calls the pane writing code the pane var that should be set in getPane is NULL and throws an exception. My overall project is pretty much just the generated template for a vspackage with no modifications besides this added bit of code.
Code:
/// <summary>
/// This function is the callback used to execute a command when the a menu item is clicked.
/// See the Initialize method to see how the menu item is associated to this function using
/// the OleMenuCommandService service and the MenuCommand class.
/// </summary>
private void MenuItemCallback(object sender, EventArgs e)
{
// Show a Message Box to prove we were here
IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
Guid clsid = Guid.Empty;
int result;
var outputWindow = GetService(
typeof(SVsOutputWindow)) as IVsOutputWindow;
IVsOutputWindowPane pane;
Guid guidGeneralPane =
VSConstants.GUID_OutWindowGeneralPane;
outputWindow.GetPane(ref guidGeneralPane, out pane);
string msg = "WRITING TO OUTPUT PANE\n";
pane.OutputString(msg);
}
Anyone know why this is happening?
Re: Writing to output pane of VS2013 in C# VsPackage fails
Well just an update, it seems to work fine when writing specifically to the BUILD output pane or creating my own, just not to the general output.
Code:
Guid guidGeneralPane =
VSConstants.GUID_BuildOutputWindowPane; // works
outputWindow.GetPane(ref guidGeneralPane, out pane);
Code:
IVsOutputWindowPane CreatePane(Guid paneGuid, string title,
bool visible, bool clearWithSolution)
{
IVsOutputWindow output =
(IVsOutputWindow)GetService(typeof(SVsOutputWindow));
IVsOutputWindowPane pane;
// Create a new pane.
output.CreatePane(
ref paneGuid,
title,
Convert.ToInt32(visible),
Convert.ToInt32(clearWithSolution));
// Retrieve the new pane.
output.GetPane(ref paneGuid, out pane);
return pane;
}
/// <summary>
/// This function is the callback used to execute a command when the a menu item is clicked.
/// See the Initialize method to see how the menu item is associated to this function using
/// the OleMenuCommandService service and the MenuCommand class.
/// </summary>
private void MenuItemCallback(object sender, EventArgs e)
{
// Show a Message Box to prove we were here
IVsUIShell uiShell = (IVsUIShell)GetService(typeof(SVsUIShell));
Guid clsid = Guid.Empty;
int result;
Guid g = new Guid("0A3A19C1-FE4A-4A49-988C-0CC8E478203A");
IVsOutputWindowPane pane;
pane = CreatePane(g, "PANE", true, true);
pane.Activate();
string msg = "WRITING TO OUTPUT PANE\n";
pane.OutputString(msg);
}