Capture build output in Visual Studio 2010

Is there a way so that I can capture the output of the assembly, i.e. text that is displayed in the output window? Right now, my only alternative to copying and pasting text from the output window is to build from the command line and redirect the output to a file.

A quick look at the C # compiler command-line options does not show any option to specify the output file for messages, such as warnings and errors, so I guess the VS hooks in the output stream of the csc.exe process to capture its text and write it to the output window. There may be a gap in which you can also connect a user application.

+7
source share
4 answers

Add the following macro to the VS EnvironmentEvent Module (Tools-> Macros-> IDE Macros ...) or ALT + F11. The macro is executed after the assembly is completed, successfully or not.

This will cause the text to exit the output window, namely the Build view of the output window in build_output.log . Other IDE Guides can be found on MSDN .

As a reference, the solution was based on the HOWTO: get the output string OutputWindowPane to output some string from a Visual Studio add-in or macro

Visual Studio provides window output ("View", "Other windows", "Exit" menu) for displaying messages, debugging information, etc. This window provides several panels that can be selected through the combo box, for example, "Source Control", "Build", "Debug", etc.

The Automation Model (EnvDTE) provides EnvDTE.OutputWindow, EnvDTE.OutputWindowPanes, and EnvDTE.OutputWindowPane Classes.

  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 

The above can be modified to possibly display construction information for each project. File names for build logs, etc., can probably be configured based on the current project (not too sure about this), and above all, you can save the build history.

There are all the VS events that you can catch on, so the type of things you can do is endless

This has been tested on the VS2010 Ultimate ...

+5
source

I think you could use DebugView or develop an application to capture output window results.

Example from MSDN for controlling the output window:

 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)); } 

Hope helps!

+3
source

I don't know if this makes it easier if you know this, but visual studios set the environment variable VS_UNICODE_OUTPUT, and this is used by the cl.exe compiler to send its output directly to VS. If you clear this variable, cl.exe output will be standard and error.

Hope this helps!

+3
source

You can use Visual Studio extensibility ( http://msdn.microsoft.com/en-us/vstudio/ff718165 ) to read the contents of the output window. In this section you can show how to get a link to it: How to write a Visual Studio output window in "My custom tool"? .

-one
source

All Articles