Okno wyjściowe
Aby napisać do okna wyjściowego „Ogólne” w Visual Studio, należy wykonać następujące czynności:
IVsOutputWindow outWindow = Package.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;
Guid generalPaneGuid = VSConstants.GUID_OutWindowGeneralPane; // P.S. There's also the GUID_OutWindowDebugPane available.
IVsOutputWindowPane generalPane;
outWindow.GetPane(ref generalPaneGuid , out generalPane);
generalPane.OutputString("Hello World!");
generalPane.Activate(); // Brings this pane into view
Jeśli jednak chcesz napisać do okna niestandardowego to co trzeba zrobić:
IVsOutputWindow outWindow = Package.GetGlobalService(typeof(SVsOutputWindow)) as IVsOutputWindow;
// Use e.g. Tools -> Create GUID to make a stable, but unique GUID for your pane.
// Also, in a real project, this should probably be a static constant, and not a local variable
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(); // Brings this pane into view
Szczegóły dotyczące IVsOutputWindow i IVsOutputWindowPane można znaleźć w witrynie MSDN.
Lista błędów
Do dodawania elementów do listy błędzie IVsSingleFileGenerator
ma wywołanie metody void Generate(...)
który ma parametr typu IVsGeneratorProgress
. Ten interfejs ma metodę void GeneratorError()
, która umożliwia zgłaszanie błędów i ostrzeżeń do listy błędów programu Visual Studio.
public class MyCodeGenerator : IVsSingleFileGenerator
{
...
public void Generate(string inputFilePath, string inputFileContents, string defaultNamespace, out IntPtr outputFileContents, out int output, IVsGeneratorProgress generateProgress)
{
...
generateProgress.GeneratorError(false, 0, "An error occured", 2, 4);
...
}
...
}
Szczegóły dotyczące GeneratorError() można znaleźć na stronie MSDN.
Dlaczego nie pisze się na standardowe wyjście działające dla Ciebie? – avakar
pisanie wiadomości do Console.Write nie daje mi nic w oknie wyjściowym. –