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
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>.
Switches for loggers. Serializes all build events to a compressed binary file. By default the file is in the current directory and named msbuild.
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.
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.
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
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