It appears msbuild writes all output (including error output) to standard output.
Is there some way to have it write error output (what's normally output in red) to standard error instead?
I'm writing a .NET application with a WPF and console interface and calling msbuild using System.Diagnostics.Process. I'd like to be able to distinguish error output to the user somehow.
Is there a better of separating the output than looking for "error " in each line or using Microsoft.Build directly + a custom logger?
Take a look at the MSBUILD.EXE command line arguments page. Specifically the consoleloggerparameters
switch.
You can use /clp:ErrorsOnly
to display only errors in the console output.
If you need the rest of the output, include an errors only file log with
/fl4 /flp4:errorsOnly;logfile=MSBuild.Errors.log
then monitor the file for new lines.
I know you said you wanted to avoid a custom logger, but... I also wanted error output on stderr and found that writing a custom logger was not that painful - 1 class with 1 method with 1 statement:
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);
};
}
}
This uses the same error formatting as msbuild. This works with command-line msbuild 14.0.25420.1. The code references Microsoft.Build.Utilities.Core.dll and Microsoft.Build.Framework.dll in C:\Program Files (x86)\MSBuild\14.0\Bin. I add /logger:ErrorOnlyLogger,path\ErrLogger.dll to the command line to invoke it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With