Is there any way to output msbuild error for stderr?

It seems that msbuild is writing all output (including error output) to standard output.

Is there any way to output a write error (which is usually displayed in red) instead of a standard error?

I am writing a .NET application with WPF and a console interface and invoking msbuild using System.Diagnostics.Process. I would like to somehow distinguish the error output from the user.

Is splitting the output better than finding an β€œerror” in each line, or using Microsoft.Build directly + user log?

+4
source share
2 answers

Take a look at the MSBUILD.EXE command line argument page. In particular, consoleloggerparameters switches.

You can use / clp: ErrorsOnly to display only errors in console output.

If you need the rest of the output, turn on the error log only with the file "/fl4/flp4:errorsOnly;logfile=MSBuild.Errors.log", check the file for new lines.

+6
source

I know that you said you want to avoid the user registrar, but ... I also wanted to get the error output to stderr and found that the user registrar record was not so painful - 1 class with 1 method with 1 expression:

using Microsoft.Build.Utilities; using Microsoft.Build.Framework; public class ErrorOnlyLogger : Logger { public override void Initialize(IEventSource eventSource) { eventSource.ErrorRaised += (s, e) => { System.Console.Error.WriteLine( "{0}({1},{2}): error {3}: {4} [{5}]", e.File, e.LineNumber, e.ColumnNumber, e.Code, e.Message, e.ProjectFile); }; } } 

In this case, the same error formatting as msbuild is used. This works with the msbuild 14.0.25420.1 command line. The code refers to the Microsoft.Build.Utilities.Core.dll and Microsoft.Build.Framework.dll files in C: \ Program Files (x86) \ MSBuild \ 14.0 \ Bin. I add /logger:ErrorOnlyLogger,path\ErrLogger.dll to the command line to call it.

+1
source

Source: https://habr.com/ru/post/1497057/


All Articles