[英]How to get Visual Studio Output Window content via EnvDTE (Non Package)
I'm writing an out of process console program that automate Visual Studio (2012). 我正在编写一个自动化Visual Studio(2012)的进程外控制台程序。 i need to get the content of the output pane either read it at once or preferably register to a notification on each line added to the output window.
我需要获取输出窗格的内容,或者一次读取它,或者最好在添加到输出窗口的每一行上注册到通知。
I've seen some examples that only apply when writing a package, but they won't apply when doing so for an out of process program. 我看到了一些仅在编写程序包时适用的示例,但对于进程外程序则不适用。
the big problem at the moment is that i can't get the output window service via GetService of a Service Provider. 目前最大的问题是我无法通过服务提供商的GetService获取输出窗口服务。 it always returns null.
它总是返回null。 I'm not sure i can get it if i'm not writing a package.
我不确定如果我没有写一个包裹我能得到它。
This seems to work for me 这似乎对我有用
public string GetOutput()
{
const string buildOutputPaneGuid = "{1BD8A850-02D1-11D1-BEE7-00A0C913D1F8}";
const string vsWindowKindOutput = "{34E76E81-EE4A-11D0-AE2E-00A0C90FFFC3}";
var outputWindow = dte.Windows.Item(/*EnvDTE.Constants.*/vsWindowKindOutput);
var outputWindowDynamic = outputWindow.Object;
foreach(OutputWindowPane pane in outputWindowDynamic.OutputWindowPanes)
{
if (pane.Guid == buildOutputPaneGuid)
{
try
{
pane.Activate();
var sel = pane.TextDocument.Selection;
sel.StartOfDocument(false);
sel.EndOfDocument(true);
return sel.Text;
}
catch (Exception ex)
{
return null;
}
}
}
return null;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.