Skip to content

Instantly share code, notes, and snippets.

@NickCraver
Created May 15, 2022 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NickCraver/e1c007da29e681b0f5c1e92d1e323dec to your computer and use it in GitHub Desktop.
Save NickCraver/e1c007da29e681b0f5c1e92d1e323dec to your computer and use it in GitHub Desktop.
MSBuild Dupe WriteChecker
// 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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment