Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

msbuild: Anyway to show summary and use verbosity=minimal

Tags:

msbuild

I have a batch file for building .net solutions and am trying to get the verbosity level to be minimal which only shows which project is building and any warnings and/or errors but would also like to see the summary at the end with number of warnings and errors plus the build time.

I have tried multiple combinations of verbosity and /v and /cpl but it seems you can only get too much output + summary or right minimal output and no summary

Any ideas?

Thanks in advance

like image 889
Adam Fox Avatar asked Oct 11 '11 16:10

Adam Fox


People also ask

How do I create a SLN file in MSBuild?

At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute. Specify the target after the -target: switch in the format <ProjectName>:<TargetName>.

What is switch in MSBuild?

Switches for loggers. Serializes all build events to a compressed binary file. By default the file is in the current directory and named msbuild.

How do I open MSBuild from command prompt?

Use MSBuild at a command prompt To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.

How do I get MSBuild command from Visual Studio?

If you have Visual Studio, then you already have MSBuild installed. With Visual Studio 2022, it's installed under the Visual Studio installation folder. For a typical default installation on Windows 10, MSBuild.exe is under the installation folder in MSBuild\Current\Bin.


1 Answers

You can write a custom logger as explained here: http://msdn.microsoft.com/en-us/library/ms171471.aspx

Here's a bit of 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 logger logs Warnings, Errors and Summarises the amount of errors and warnings. You'll need to add a little bit of code for time and projects, so that it is exactly what you want.

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

/nologo /noconsolelogger /logger:pathTo/SummaryLogger.dll
like image 72
Didier A. Avatar answered Nov 15 '22 06:11

Didier A.