Skip to content

Instantly share code, notes, and snippets.

@TheAngryByrd
Created March 6, 2025 14:53
Show Gist options
  • Save TheAngryByrd/a2ec1a2cade0d4c3f4c53d5e42b362a2 to your computer and use it in GitHub Desktop.
Save TheAngryByrd/a2ec1a2cade0d4c3f4c53d5e42b362a2 to your computer and use it in GitHub Desktop.
Figure out why CoreCompile was run
// This is used to quickly diagnose why a rebuild happened in a large solution
// It reads a binlog file and finds all the CoreCompile targets that were triggered by a file being newer than the output file
// It then prints out the project and the messages that caused the rebuild
// to create a binlog you can refer to https://learn.microsoft.com/en-us/visualstudio/ide/msbuild-logs?view=vs-2022#provide-msbuild-binary-logs-for-investigation
// CLI: dotnet build -bl:mybinlog.binlog
// or in `.build/build.fs` add `BuildParameter.enableBinLog "mybinlog.binlog"` to the `build'` target.
// Use https://msbuildlog.com/ to diagnose further
#r "nuget: MSBuild.StructuredLogger"
open Microsoft.Build.Logging.StructuredLogger
/// Update your binlog path here
let binlog = "path/to/binlog.binlog"
let build = Serialization.Read binlog
let (|Message|_|) (b : BaseNode) =
match b with
| :? Message as m -> Some m
| _ -> None
let causations =
build
.FindChildrenRecursive<Target>(fun t ->
t.Name = "CoreCompile"
&& t.Children
|> Seq.exists(function Message m -> m.ToString().Contains "is newer than" | _ -> false)
)
causations
|> Seq.sortBy(fun t -> t.StartTime)
|> Seq.iter (fun t ->
printfn $"{t.Project} {t.Name}"
t.Children
|> Seq.iter(fun x -> printfn $" {x}" )
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment