// Inspired by https://github.com/dotnet/roslyn/blob/main/src/Tools/BuildBoss/StructuredLoggerCheckerUtil.cs#L33 // Licensed to the .NET Foundation under one or more agreements. using System; using Microsoft.Build.Logging.StructuredLogger; // Invokes the analyzer here: // https://github.com/KirillOsenkov/MSBuildStructuredLog/blob/master/src/StructuredLogger/Analyzers/DoubleWritesAnalyzer.cs string _logFilePath = System.IO.Path.GetFullPath(args[0]); Console.WriteLine($"Running MSBuild binlog checks for '{_logFilePath}'"); try { bool doubleWritesPresent = false; var build = Serialization.Read(_logFilePath); if (!build.Succeeded) { Console.Error.WriteLine($" Error reading binlog at '{_logFilePath}'"); return 2; } foreach (var doubleWrite in DoubleWritesAnalyzer.GetDoubleWrites(build)) { doubleWritesPresent = true; Console.Error.WriteLine($" Multiple writes to {doubleWrite.Key}"); foreach (var source in doubleWrite.Value) { Console.Error.WriteLine($" {source}"); } Console.Error.WriteLine(); } if (!doubleWritesPresent) { Console.WriteLine(" No duplicate writes found."); return 0; } return 1; } catch (Exception ex) { Console.Error.WriteLine($" Error processing binary log file: {ex.Message}"); return 3; }