Msbuild: Anyway, to show a resume and use verbosity = minimum

I have a batch file for building .NET solutions, and I'm trying to get the verbosity level to a minimum, which only shows which project is being built and which warnings and / or errors, but would also like to get a summary at the end with the number of warnings and errors plus build time.

I tried several combinations of verbosity and / v and / cpl, but it seems that you can get too much result + summary or right minimum output and without summary

Any ideas?

Thanks in advance

+7
source share
2 answers

You can write your own journal as described here: http://msdn.microsoft.com/en-us/library/ms171471.aspx

Here is some code to get you started:

public class SummaryLogger : Logger { int warningCount = 0; int errorCount = 0; public override void Initialize(IEventSource eventSource) { eventSource.WarningRaised += eventSource_WarningRaised; eventSource.ErrorRaised += eventSource_ErrorRaised; eventSource.BuildFinished += eventSource_BuildFinished; } void eventSource_WarningRaised(object sender, BuildWarningEventArgs e) { warningCount++; Console.WriteLine("Warning: " + e.Message); } void eventSource_ErrorRaised(object sender, BuildErrorEventArgs e) { errorCount++; Console.WriteLine("Error: " + e.Message); } void eventSource_BuildFinished(object sender, BuildFinishedEventArgs e) { Console.WriteLine("MSBuild Finished: " + errorCount + " errors | " + warningCount + " warnings."); } } 

This log logs warnings, errors and summarizes the number of errors and warnings. You need to add some code for time and projects, so this is exactly what you want.

To use it, you call MSBuild with the following parameters added:

 /nologo /noconsolelogger /logger:pathTo/SummaryLogger.dll 
+3
source

one thought would be to extract the necessary information from the log file.

Like this,

 Step 1: Redirect your msbuild outputs to a log.txt Step 2: At the end of the batch file run findstr cmd to look for desired text 

Example:

 @echo off setlocal ... MSBuild /nologo [path to project1 or sln1] [options] >> log.txt ... MSBuild /nologo [path to project2 or sln2] [options] >> log.txt ... findstr /irc:"Build*" /c:".*Warning(s)" /c:".*Error(s)" /c:"Time Elapsed.*" log.txt 

Hope this helps!

+1
source

All Articles