有没有办法可以捕获构建输出,即输出到输出窗口的文本?现在,我唯一可以从输出窗口复制和粘贴文本的替代方法是从命令行构建并将输出重定向到文件。
快速查看C#编译器命令行选项并未显示为警告和错误等消息指定输出文件的任何选项,因此我猜测VS钩子进入csc.exe进程的输出流,以捕获其文本并将其写入输出窗口。也许自定义应用程序也可能存在差距。
答案 0 :(得分:5)
将以下宏添加到VS EnvironmentEvent
模块(工具 - >宏 - >宏IDE ...)或ALT + F11。无论是否成功,构建完成后都会运行宏。
这会将输出窗口的文本输出,更具体地说是输出窗口的Build
视图传递给build_output.log
。其他IDE Guids can be found on MSDN。
作为参考,解决方案基于HOWTO: Get an OutputWindowPane to output some string from a Visual Studio add-in or macro
Visual Studio提供输出 窗口(“查看”,“其他Windows”, “输出”菜单)显示消息,调试 该窗口提供的信息等 几个可以选择的窗格 通过组合框,例如“Source 控制“,”构建“,”调试“等。
自动化模型(EnvDTE)提供 EnvDTE.OutputWindow, EnvDTE.OutputWindowPanes和 EnvDTE.OutputWindowPane类。
Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildDone
Const BUILD_OUTPUT_PANE_GUID As String = "{1BD8A850-02D1-11D1-BEE7-00A0C913D1F8}"
Dim t As OutputWindowPane
Dim txtOutput As TextDocument
Dim txtSelection As TextSelection
Dim vsWindow As Window
vsWindow = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
Dim vsOutputWindow As OutputWindow
Dim objOutputWindowPane As OutputWindowPane
Dim objBuildOutputWindowPane As OutputWindowPane
vsOutputWindow = DirectCast(vsWindow.Object, OutputWindow)
For Each objOutputWindowPane In vsOutputWindow.OutputWindowPanes
If objOutputWindowPane.Guid.ToUpper = BUILD_OUTPUT_PANE_GUID Then
objBuildOutputWindowPane = objOutputWindowPane
Exit For
End If
Next
txtOutput = objBuildOutputWindowPane.TextDocument
txtSelection = txtOutput.Selection
txtSelection.StartOfDocument(False)
txtSelection.EndOfDocument(True)
objBuildOutputWindowPane.OutputString(Date.Now)
txtSelection = txtOutput.Selection
solutionDir = IO.Path.GetDirectoryName(DTE.Solution.FullName)
My.Computer.FileSystem.WriteAllText(solutionDir & "\build_output.log", txtSelection.Text, False)
MsgBox(txtSelection.Text)
End Sub
以上内容可以调整为可能在每个项目的基础上输出构建信息。可以根据正在构建的当前项目来配置构建日志等的文件名(对此不太确定),最重要的是,您可以保留构建历史记录。
有一个可以挂钩的VS事件,所以人们可以做的事情是无穷无尽的
这是在VS2010 Ultimate上测试的......
答案 1 :(得分:3)
我认为您可以使用DebugView或开发应用程序来捕获输出窗口结果。
MSDN管理输出窗口的示例:
public void writeReadOW(DTE2 dte)
{
// Add-in code.
// Create a reference to the Output window.
// Create a tool window reference for the Output window
// and window pane.
OutputWindow ow = dte.ToolWindows.OutputWindow;
OutputWindowPane owP;
// Create a reference to the pane contents.
TextDocument owPTxtDoc;
EditPoint2 strtPt;
// Select the Build pane in the Output window.
owP = ow.OutputWindowPanes.Item("Build");
owP.Activate();
owPTxtDoc = owP.TextDocument;
// Put some text in the pane.
owP.OutputString("Testing 123.");
// Retrieve the text contents of the pane.
System.Windows.Forms.MessageBox.Show("Startpoint: " +
owPTxtDoc.StartPoint.DisplayColumn);
strtPt = (EditPoint2)owPTxtDoc.StartPoint.CreateEditPoint();
System.Windows.Forms.MessageBox.Show
(strtPt.GetText(owPTxtDoc.EndPoint));
}
希望有所帮助!
答案 2 :(得分:3)
如果您知道这一点,我不知道这是否会让事情变得更容易,但是visual studio会设置一个环境变量VS_UNICODE_OUTPUT,cl.exe编译器会将其用于直接将其输出发送给VS.如果清除此变量,cl.exe输出将转为标准输出并输出错误。
希望有所帮助!
答案 3 :(得分:-1)
您可以使用Visual Studio可扩展性(http://msdn.microsoft.com/en-us/vstudio/ff718165)来读取输出窗口的内容。本主题可以说明如何获取对它的引用:How do I write to the Visual Studio Output Window in My Custom Tool?。