Skip to content

Support binlog format v28: structured RAR diagnostic events (read-only) - #969

Merged
KirillOsenkov merged 14 commits into
KirillOsenkov:mainfrom
martin-strecker-sonarsource:martin-strecker-sonarsource/format-v28-rar-events
Oct 27, 2026
Merged

KirillOsenkov merged 14 commits into
KirillOsenkov:mainfrom
martin-strecker-sonarsource:martin-strecker-sonarsource/format-v28-rar-events

Conversation

@martin-strecker-sonarsource

@martin-strecker-sonarsource martin-strecker-sonarsource commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #968

Summary

dotnet/msbuild#14599 and #14601 replaced ResolveAssemblyReference's (RAR) plain-text diagnostics with three structured record kinds, bumping the binlog format to v28: AssemblyResolutionSearchTrace, AssemblyConflictDependencyDetails, AssemblyConflictWarning. These are reachable today via ChangeWave 18.12 (VS Insiders builds); the MSBuild team confirmed on #968 that the format is frozen for GA.

Without support for these, they collapse into one generic "Skipped some data unknown to this version of Viewer" warning and all their content is lost.

  • AssemblyResolutionSearchTrace - one event per RAR reference, replacing the dozens of per-candidate plain-text messages this aggregates (file tried, search path, parent assembly, result, processor arch).
  • AssemblyConflictDependencyDetails / AssemblyConflictWarning - the structured replacement for the legacy free-text MSB3277 "conflict" diagnostics.

Scope: reader-only

This adds read support only - no BuildEventArgsWriter path for these three kinds. This follows the precedent set by #955, which added the last new record kind (MSBuildServerLifecycle, for format v27) with reader support only. Known consequence, same as that precedent today: these events won't survive a redact/merge round-trip through this project (e.g. the Viewer's redaction feature, or BinlogTool merge).

The three new event classes are local shims in the Microsoft.Build.Framework namespace (see AssemblyResolutionSearchTraceEventArgs.cs, AssemblyConflictReferenceDetails.cs, AssemblyConflictDependencyDetailsMessageEventArgs.cs, AssemblyConflictWarningEventArgs.cs), again mirroring MSBuildServerLifecycleEventArgs.cs - this project pins Microsoft.Build.Framework to 17.5.0, well below the version that will eventually define the real types, so it can't reference them yet. They're trimmed to the fields actually read off the wire; this fork doesn't implement the real types' localized Message formatting - Message is a simple invariant summary, computed lazily on first access like AssemblyLoadBuildEventArgs's does.

Rendering

Reuses existing node types rather than inventing new ones or reproducing the legacy text layout exactly:

  • AssemblyResolutionSearchTrace → one Item child per search attempt, appended directly onto the Parameter node that RAR's own "Primary reference"/"Dependency" header message already created under the task's Results folder. MSBuild logs that header unconditionally alongside the new structured event, so attaching there - rather than creating a new standalone node - keeps each reference's search trace attached to that same reference instead of floating detached on the task.
  • AssemblyConflictDependencyDetails gets the same attach-point treatment, merging its Victor/Victim detail onto that same Results Parameter. AssemblyConflictWarning → a Warning node via the same path Construction.WarningRaised already uses for RAR conflicts, but building the child tree directly from the structured Victor/Victim fields instead of regex-matching rendered text.
  • ItemGroupParser.AddConflictReferenceDetails - shared by both conflict event kinds - mirrors MSBuild's own AssemblyConflictMessageFormatter.AppendReferenceDetails: besides FusionName and each dependee's path, it also surfaces the reference's own FullPath, PrimarySourceItemSpecs/UnresolvedPrimaryItemSpec, and each dependee's SourceItemSpecs; LossReason is rendered as a property on the warning node. It's the structured-data counterpart of ItemGroupParser.ParseThereWasAConflict, which does the same from legacy free text.

Known simplification: the legacy text distinguished "primary reference" vs "dependency" vs "unified" via separate regexes; the new structured events don't carry that categorization in the same shape, so this PR doesn't attempt to reproduce that distinction.

StructuredLogViewer_48IcPLmsC3

conflict.zip

See this comment for details on how the binlog above was produced (including a side note on why Other/mscorlib/System.* don't appear under OutputItems in the screenshot).

Testing

Added three tests in BinaryLoggerTests.cs that hand-construct the exact wire bytes (field order taken from dotnet/msbuild's own writer) and feed them directly into BuildEventArgsReader, since there's no production Write(...) path to round-trip through. To keep the hand-written framing simple, these construct the reader with fileFormatVersion: 9 (pre-dedup, pre-length-framing) - see the comment block above the tests for why that's safe and doesn't affect the new record kinds' field layout.

Also verified against a real binlog: installed a .NET 11 RC2 SDK and reproduced all three record kinds with an actual build (that's what the screenshot above is from). Fed the resulting binlog through BuildEventArgsReader directly and through the full tree-building pipeline (Serialization.Read → MessageProcessor/Construction), and confirmed all three decode and render correctly, including the real MSB3277 warning with its Victor/Victim folders shown above. Repro steps are in this comment.

  • dotnet test src/StructuredLogger.Tests passes (105 tests, including the 3 new ones)
  • Full solution builds (dotnet build MSBuildStructuredLog.sln), including the Viewer apps
  • Manually verified against a real RC2-produced binlog (see above)

🤖 Generated with Claude Code

dotnet/msbuild#14599 and #14601 replaced ResolveAssemblyReference's plain-text
diagnostics with three structured record kinds (AssemblyResolutionSearchTrace,
AssemblyConflictDependencyDetails, AssemblyConflictWarning), currently reachable
via ChangeWave 18.12 / VS Insiders builds. Without this, those records collapse
into one generic "Skipped some data unknown to this version of Viewer" warning.

Adds reader support only, matching the precedent set for MSBuildServerLifecycle
(the last new record kind, added for format v27): no BuildEventArgsWriter path,
so these events won't survive a redact/merge round-trip through this project.
Local shim classes live in the Microsoft.Build.Framework namespace since this
project pins that package well below the version that defines the real types.

Rendering reuses existing node types (Parameter/Item for the search trace,
Warning/Folder/Item for conflicts - the structured-data counterpart of
ItemGroupParser.ParseThereWasAConflict's legacy text parsing) rather than
reproducing the old primary/dependency/unified categorization.

See KirillOsenkov#968.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@baronfel

Copy link
Copy Markdown
Collaborator

Thanks for starting this! I'd suggest using an RC2 SDK to get a sample binlog to verify the ability to read, and I'd also strongly consider not eagerly hydrating the messages. The reader is often used in high efficiency scenarios and doing additional work if any kind should be avoided.

Attempt 2 now reuses attempt 1's SearchPath/ParentAssembly/IsAssemblyFoldersExSearch
via the SearchPathUnchanged/ParentAssemblyUnchanged/AssemblyFoldersExUnchanged bits
instead of re-writing identical values, matching the real compression this record
kind relies on and dropping three now-redundant writes.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…uplicate

Microsoft.Build.Shared.BinaryWriterExtensions.WriteOptionalString already writes
the exact byte-for-byte format BuildEventArgsReader.ReadOptionalString() expects
pre-v10 (presence byte + string). Also switch the search-trace attempt assertions
to SatisfyRespectively instead of indexed Should() calls.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
- Convert AssemblyConflictDependee/AssemblyConflictReferenceDetails to primary
  constructors, matching this repo's own precedent (BuildCheckTracingEventArgs,
  BuildCheckAcquisitionEventArgs).
- Drop public setters on the three event-args classes' properties - they're
  only ever assigned once, from the reader's constructor call.
- Fix line endings/BOM on all four new files (LF/no-BOM) to match
  .editorconfig's end_of_line=crlf and charset=utf-8-bom for *.cs.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
None of this fork's existing Read*EventArgs methods cite where their wire
format comes from, but we have a concrete source to point at for these three,
so add it rather than leave the same gap.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
- AssemblyResolutionSearchAttempt, AssemblyConflictWarningEventArgs, and
  AssemblyConflictDependencyDetailsMessageEventArgs converted to primary
  constructors, dropping their unused parameterless constructors in the
  process.
- AssemblyConflictDependee/AssemblyConflictReferenceDetails tightened from
  { get; private set; } to { get; }, consistent with the earlier fix to the
  event-args classes' properties.
- BuildEventArgsReader's new Read* methods switched explicit string/bool
  locals to var, matching this file's dominant style (int count locals left
  explicit, matching that recurring idiom elsewhere in the file).
- Construction.cs: reworded the AssemblyConflictWarningEventArgs branch's
  comment to name the specific regex/parser it bypasses (Strings.IsFoundConflicts,
  ItemGroupParser.ParseThereWasAConflict) instead of referring to it only as
  "rendered text".

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Per KirillOsenkov#969 (comment):
this reader is used in high-throughput scenarios, so eagerly formatting Message
in the constructor (string interpolation work on every event, even when nobody
reads Message) should be avoided. All three event-args classes now compute
Message lazily on first access and cache it in RawMessage, matching the
existing AssemblyLoadBuildEventArgs precedent in this fork.

Also: use raw string literals for the three Message formats (no more \" escapes),
and fix a few test literals that used "C:\proj\..." instead of this file's
usual @"C:\proj\..." verbatim style.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@martin-strecker-sonarsource

martin-strecker-sonarsource commented Oct 22, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the feedback — both addressed.

Lazy Message: pushed in a1d089f. All three new event types now defer formatting to first Message access via the inherited RawMessage field, following the same pattern AssemblyLoadBuildEventArgs already uses in this repo.

Verified against a real RC2 binlog: Installed 11.0.100-rc.2.26504.105 and reproduced all three record kinds with a real build. Repro, in case it's useful to anyone else (or as a starting point for an automated test — see note below):

  1. global.json pinning the RC2 SDK.
  2. Two tiny net48 class libraries, ClassLibA and ClassLibB, each with a <Reference Include="Shared"> to a different, strong-named build of a third assembly (Shared.dll v1.0.0.0 vs v2.0.0.0, same .snk), and — importantly — actual code using a type from Shared in each. (An unused reference gets elided by the C# compiler and never shows up as an AssemblyRef in the compiled metadata, so RAR's dependency walk has nothing to find — this tripped me up for a while.)
  3. A small non-SDK .proj file that invokes ResolveAssemblyReference directly (bypassing the SDK's own target layering for full control), mirroring the shape of this repo's own AssemblyConflictLogging_Tests.CreateWarningConflictTask fixture:
    <ResolveAssemblyReference
        Assemblies="@(MyRef)"  <!-- ClassLibA, ClassLibB, and Shared v1.0.0.0 as an explicit primary -->
        SearchPaths="{HintPathFromItem};<SharedV1 dir>;<SharedV2 dir>;{TargetFrameworkDirectory}"
        AutoUnify="false"
        FindDependencies="true" />
    Pinning Shared v1.0.0.0 as an explicit primary (in addition to it being a transitive dependency of ClassLibA) reproduces the "victor is both primary and a dependency" shape from that same fixture, and the strong-naming is what actually pushes it past the auto-unify message path into the real MSB3277 warning. (Strong naming matters because the CLR only enforces strict version identity for strong-named assemblies — a mismatch there is a genuine runtime load risk without a binding redirect, which is exactly what MSB3277 warns about. Unsigned assemblies have no such identity check, so RAR treats the same conflict as a low-importance bookkeeping note instead.)
  4. dotnet msbuild conflict-repro.proj -t:Build -bl:conflict.binlog with the pinned RC2 SDK.

Fed the resulting binlog through BuildEventArgsReader and confirmed all three kinds decode correctly:

  • AssemblyResolutionSearchTrace — requested name, search attempts, and result enum all correct.
  • AssemblyConflictDependencyDetails — Victor/Victim fusion names correct.
  • AssemblyConflictWarning — SimpleAssemblyName, LossReason, Code (MSB3277), Victor/Victim with their Dependees, and the lazy Message — all correct, matching the real console warning text.

I didn't commit the binlog itself or turn this into an automated test — this repo doesn't check in sample binlogs anywhere (*.binlog is gitignored; existing tests build fresh in-process), and dotnet/msbuild's own tests for this feature don't use real builds either, they drive ResolveAssemblyReference directly with fixture data. Happy to add an automated test along those lines if you'd like one — just say the word.

One side note on the screenshot/binlog attached to the PR description: Other (and mscorlib/System.*) deliberately don't show up under OutputItems there. That's just an artifact of the minimal hand-written .proj - ResolvedFiles only reflects the primary Assemblies input list, and I never wired up RAR's ResolvedDependencyFiles output to an item there. Not a gap in the new reader/rendering code - Other's conflict is still fully visible via its own AssemblyConflictDependencyDetails message node, just not duplicated in that output-items listing.

@KirillOsenkov

Copy link
Copy Markdown
Owner

Hey Martin, thanks for doing this!

If you like I can take over and finish this, or you can respond to my feedback, whatever you prefer.

Basically I just found out that the past couple of version bumps we never incremented the version, so we need to bump the FileFormatVersion to 28 and add comments for 26, 27 and 28. PR #955 forgot this too.

Rendering: RAR still logs the “Primary reference ...” and “There was a conflict between ...” headers as plain text in the new change wave, and ProcessRAR still turns those into Parameter nodes under Results. The new nodes are added to the task itself, so each reference and each conflict now shows up twice, detached from each other. Please attach the search trace and the dependency details to the last Parameter in rar.Results, the same way the indented-line path does, so the tree looks like it did before. For the items, use the Framework resource text (“For SearchPath ...”, “Considered ..., but it didn’t exist.”, “References which depend on ...”, “Project file item includes which caused reference ...”) instead of enum names and “Victor”/”Victim” labels.

AddConflictReferenceDetails drops most of the data: the loss reason line, FullPath, PrimarySourceItemSpecs, each dependee’s SourceItemSpecs, and UnresolvedPrimaryItemSpec. The legacy text tree showed all of those. Mirroring AssemblyConflictMessageFormatter.AppendReferenceDetails from MSBuild would make it lossless.

Nice to have: add the three Write overloads to BuildEventArgsWriter (small, mirrors MSBuild) so redact/merge keeps the data and the tests can round-trip through the real v28 framing instead of version 9. Also the doc comments still say “simple eager summary, computed lazily”.

(disclaimer: I used Fable to review)

…e's Parameter

Per Kirill's review on KirillOsenkov#969: the new AssemblyResolutionSearchTrace and
AssemblyConflictDependencyDetails nodes were being added directly as children
of the RAR task, detached from the legacy "Primary reference"/"Dependency"/
conflict-header Parameter under task.Results that MSBuild still logs
unconditionally alongside the new structured events. Each reference/conflict
ended up represented by two disconnected nodes instead of one.

Now both event kinds attach onto Results' last Parameter (the same one the
indented-line legacy path nests onto), matching how the tree looked before
format v28. Falls back to a standalone node only if Results doesn't exist yet.

Verified against a real binlog produced by an RC2 SDK build (not just the
hand-written wire-format tests): search-trace items land correctly under their
reference's Parameter with no detached duplicate, and the conflict-details
Victor/Victim folders merge onto the same Parameter the legacy conflict-header
text created, adding detail that low-importance legacy text didn't carry.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Per Kirill's review on KirillOsenkov#969: AddConflictReferenceDetails only rendered a
reference's FusionName and its dependees' full paths, dropping the reference's
own FullPath, PrimarySourceItemSpecs/UnresolvedPrimaryItemSpec, and each
dependee's SourceItemSpecs - all present on the structured
AssemblyConflictReferenceDetails/AssemblyConflictDependee shim classes but
never read. LossReason (carried on AssemblyConflictWarningEventArgs itself,
not on the reference details) was similarly never surfaced.

Mirrors dotnet/msbuild's AssemblyConflictMessageFormatter.AppendReferenceDetails
structurally: a reference's own FullPath is rendered the same way as a
dependee's FullPath (as an Item), with PrimarySourceItemSpecs nested under it
when the reference is a resolved primary, or UnresolvedPrimaryItemSpec as a
sibling property when it's an unresolved primary; each dependee's
SourceItemSpecs nest under its own FullPath item the same way. LossReason is
added as a Property directly on the warning node.

Verified against the same real RC2-SDK binlog used for the earlier rendering
fix: Shared's MSB3277 warning now shows LossReason = WasNotPrimary, and both
Shared's and Other's Victor/Victim folders show the full dependency chain
(FullPath + nested source item specs) that was previously dropped.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…6/27

Per Kirill's review on KirillOsenkov#969: FileFormatVersion was stuck at 25 - never bumped
when this fork added reader support for v26 (LoggersRegisteredEventArgs) or
v27 (MSBuildServerLifecycleEventArgs, PR KirillOsenkov#955), and PR KirillOsenkov#955 made the same
omission before this one. BinLogReader.EnsureFileFormatVersionKnown only
rejects a file when fileFormatVersion > FileFormatVersion AND
minimumReaderVersion > FileFormatVersion, so this was latent rather than
immediately visible: every binlog produced so far has kept minimumReaderVersion
well below 25, since v26/v27/v28 are all forward-compatible additions. A
future binlog that set minimumReaderVersion above 25 for a genuinely
non-forward-compatible reason would have been wrongly rejected by this reader
even though its Read* support for the relevant record kinds already exists.

Comments for versions 26-28 copied verbatim from dotnet/msbuild's own
BinaryLogger.cs (fetched directly via its raw GitHub URL to confirm the exact
text, not from a prior summary). Left the pre-existing v24/v25 comments
untouched - their wording already differs slightly from upstream's, but
that's unrelated to this change.

Deliberately did not copy upstream's "keep BuildEventArgsWriter and
StructuredLogViewer.BuildEventArgsWriter in sync" note: that refers to a
writer duplicated between MSBuild's own build engine and its Visual Studio
log-viewer feature, which doesn't exist in this fork (exactly one
BuildEventArgsWriter class here) - copying it would describe a problem this
codebase doesn't have.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
…classes

Per Kirill's review on KirillOsenkov#969: leftover from before the lazy-formatting fix
(commit a1d089f) - "simple eager summary, computed lazily" contradicted
itself. Drop "eager".

Co-Authored-By: Claude Sonnet 5 <[email protected]>
@martin-strecker-sonarsource

martin-strecker-sonarsource commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review, and sorry for the delay in getting back to you!

I went through all of it and pushed fixes for everything except two pieces that make more sense for you to finish:

Fixed:

  • Version bump (f5545aec): FileFormatVersion → 28, backfilled the comments for 26/27/28 (copied verbatim from your own BinaryLogger.cs).
  • Rendering duplication/detachment (1114cd5b): the search trace and conflict-dependency-details nodes now attach onto the last Parameter in rar.Results, same as the indented-line path. Verified against a real binlog from an RC2 build, not just the hand-written reader tests — one thing I noticed while verifying: the legacy plain-text conflict message and the new structured event aren't actually mutually exclusive under the change wave for non-warning conflicts, they both fire for the same conflict (only the per-candidate search-result loop is truly skipped). The fix handles that fine either way — it just finds the Parameter the legacy header already created and merges onto it — but figured it's worth flagging in case it's relevant elsewhere.
  • Lossless conflict details (45d29128): AddConflictReferenceDetails now surfaces FullPath, PrimarySourceItemSpecs/UnresolvedPrimaryItemSpec, and each dependee's SourceItemSpecs, structured the same way AppendReferenceDetails does. LossReason is now a property on the warning node too.
  • Stale doc comment (bea5a772): dropped "eager" from the three shim classes' doc comments.

The PR description is updated to reflect the current state - new screenshot, new binlog zip, and the Rendering section rewritten to match the actual current behavior.

Handing the rest over to you:

  • Framework resource text. Dug into ResourcesGenerator to add this properly and it doesn't fit cleanly: it pulls strings via reflection over a real locally-installed MSBuild, and its hardcoded DLL list doesn't include Microsoft.Build.Framework.dll (where these strings actually live, in SR.resx), and its Roslyn\Microsoft.CodeAnalysis.dll path assumes a VS layout that doesn't match an SDK-only install (crashes with no try/catch). Only an RC2+/Insiders install even has these strings compiled in anyway, and those typically only ship English resources, not the full satellite set the generator expects for the other ~12 cultures. For what it's worth, I confirmed the actual English text directly against your SR.resx, so it doesn't need re-deriving:
    • AssemblyResolutionSearchTrace_SearchPath: For SearchPath "{0}".
    • AssemblyResolutionSearchTrace_ConsideredAndRejectedBecauseNoFile: Considered "{0}", but it didn't exist.
    • (plus the other AssemblyResolutionSearchTrace_ConsideredAndRejectedBecause*/_SearchedAssemblyFoldersEx/_TargetedProcessorArchitectureDoesNotMatch variants, and AssemblyConflict_ReferenceDependsOn/_UnifiedReferenceDependsOn/_UnResolvedPrimaryItemSpec/_PrimarySourceItemsForReference for the Victor/Victim labels)
  • The BuildEventArgsWriter overloads — the "nice to have" you called them, never attempted.

Taking you up on your offer to take over for those two — thanks again for the thorough review.

@KirillOsenkov
KirillOsenkov merged commit 8ccbbd3 into KirillOsenkov:main Oct 27, 2026
1 check passed
@KirillOsenkov

Copy link
Copy Markdown
Owner

Thanks!

@KirillOsenkov

Copy link
Copy Markdown
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support binlog format v28: structured RAR diagnostic events (AssemblyResolutionSearchTrace, AssemblyConflictDependencyDetails, AssemblyConflictWarning)

3 participants