Skip to content

Preserve direct inner-build edges in static graph#14395

Open
AlesProkop wants to merge 1 commit into
dotnet:mainfrom
AlesProkop:alesprokop/fix-static-graph-direct-inner-reference
Open

Preserve direct inner-build edges in static graph#14395
AlesProkop wants to merge 1 commit into
dotnet:mainfrom
AlesProkop:alesprokop/fix-static-graph-direct-inner-reference

Conversation

@AlesProkop

@AlesProkop AlesProkop commented Jul 16, 2026

Copy link
Copy Markdown
Member

Fixes #14325

Context

Static graph construction failed when a project referenced both a multitargeted project's outer build and one of its generated inner builds directly. ProjectInterpretation.AddInnerBuildEdges assumed an existing inner-build edge could only be transitive, even when it came from an explicit ProjectReference.

Changes Made

  • Preserve an explicit ProjectReference edge when outer-build expansion reaches the same inner-build node.
  • Retain replacement behavior for _TransitiveProjectReference edges and validation for unexpected edge types.
  • Merge target requirements from the explicit inner-build reference and the generated outer-build edge.
  • Add coverage for empty, mixed, and explicit Targets metadata.

Testing

  • Ran DirectInnerBuildReferenceIsPreservedWhenOuterBuildGeneratesTheSameEdge on net10.0 — 4 passed, 0 failed.
  • Reverted only the production graph-edge change and reran the test — all 4 cases failed with the original MSB0001: Only transitive references may reference inner builds that got generated by outer builds error.

The general fix that surfaces critical graph-build exceptions instead of hanging is split into #14461.

Preserve explicit inner-build references when outer-build expansion produces the same graph edge, and merge their target requirements.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: bd403e09-8890-421f-ab7c-83eaac6d05b1
@AlesProkop
AlesProkop marked this pull request as ready for review July 16, 2026 12:19
Copilot AI review requested due to automatic review settings July 16, 2026 12:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes static graph construction for multi-targeting scenarios where a project references both an outer build and a specific inner build directly, ensuring explicit ProjectReference edges aren’t incorrectly treated as “must be transitive” and removed during outer-build expansion.

Changes:

  • Updates ProjectInterpretation.AddInnerBuildEdges to preserve explicit ProjectReference edges to inner builds while continuing to replace _TransitiveProjectReference edges.
  • Keeps a defensive assertion for unexpected edge item types when an inner-build edge already exists.
  • Adds a parameterized unit test validating edge preservation, target-metadata merging, and resulting target lists across several Targets metadata combinations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/Build/Graph/ProjectInterpretation.cs Adjusts inner-build edge expansion logic to keep explicit inner-build ProjectReference edges and only remove/replace transitive ones.
src/Build.UnitTests/Graph/ProjectGraph_Tests.cs Adds coverage for preserving direct inner-build references when outer-build expansion generates the same edge, including target list behavior.

@AlesProkop
AlesProkop force-pushed the alesprokop/fix-static-graph-direct-inner-reference branch from c9d9250 to f7ab99b Compare July 20, 2026 14:00
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.

Static graph build hangs when a project references both an outer build and an inner build directly

2 participants