Skip to content

Predict RID-agnostic project references in isolated graph builds - #15744

Open
AlesProkop wants to merge 2 commits into
dotnet:mainfrom
AlesProkop:alesprokop-isolated-rid-graph-build
Open

AlesProkop wants to merge 2 commits into
dotnet:mainfrom
AlesProkop:alesprokop-isolated-rid-graph-build

Conversation

@AlesProkop

Copy link
Copy Markdown
Member

Related issue(s): Fixes #15711

Context

dotnet build -graph -isolate -r <rid> fails with MSB4252 for a console app referencing a plain class library. At execution time, _GetProjectReferenceTargetFrameworkProperties finds that the library is IsRidAgnostic and builds it without RuntimeIdentifier/SelfContained. The static graph, however, created the library node with those properties inherited, so isolation rejects the undeclared reference configuration.

Changes Made

  • ProjectInterpretation.GetReferences: when enabled, evaluate each reference that follows the common reference protocol without RuntimeIdentifier/SelfContained, the same way GetTargetFrameworks does. If it is RID-agnostic under the same rules as the targets (IsRidAgnostic, else no RuntimeIdentifier/RuntimeIdentifiers), create the graph node without those properties. For multitargeted references, every inner build must be RID-agnostic, because nearest-framework selection happens at execution time.
  • The prediction is skipped for references with SkipGetTargetFrameworkProperties=true, SetTargetFramework, .vcxproj/.nativeproj defaults, dynamic platform resolution, outer-build requesters, and projects that don't use the common Build/GetTargetFrameworks protocol.
  • GraphBuilder reuses the cached discovery evaluation for the node, so nothing is evaluated twice.
  • Enabled only from BuildManager for isolated graph builds (ProjectIsolationMode.True) that build only the Build target and have a single entry point, via an internal ProjectGraphOptions.PredictRidAgnosticReferences. The public ProjectGraph construction and restore graphs are unchanged.

Compatibility

Gated behind ChangeWave 18.15 (documented in ChangeWaves.md). Only isolated graph builds are affected. Non-isolated graph builds, non-graph builds, and builds without a RID are unchanged.

Known limitation: a RID-sensitive library (for example, one that sets RuntimeIdentifiers) referenced this way still fails with MSB4252, as before. Supporting it would need separate discovery and build configurations.

Testing

  • build.cmd -v quiet: 0 warnings, 0 errors.
  • ProjectReferenceTargetsProtocolTests: 46/46 on net11.0 and net472, including new tests for in-proc and out-of-proc isolated builds, metadata and multitargeting cases, and multiple entry points. The wave-disabled case asserts MSB4252.
  • Microsoft.Build.Graph.UnitTests namespace: 644 passed, 8 skipped, 0 failed (net11.0 + net472). *IsolateProjects*: 88 passed, 0 failed.
  • Local end-to-end with the bootstrap SDK (dotnet restore app -r win-x64, then dotnet build app -graph -isolate -r win-x64 --no-restore):
    • The stock SDK fails with MSB4252. The patched build succeeds and the app runs. With MSBUILDDISABLEFEATURESFROMVERSION=18.15, MSB4252 returns.
    • Incremental, self-contained, linux-x64 cross-RID, Release, transitive app→lib→lib2, and a multitargeted net11.0;netstandard2.1 lib all pass.
    • Non-isolated graph, non-graph, and no-RID builds are unchanged.
    • A RID-sensitive lib (RuntimeIdentifiers set) still fails (the known limitation above).

In isolated graph builds, a project reference that the SDK considers
RID-agnostic is built without RuntimeIdentifier and SelfContained, but
the graph created its node with the inherited properties, causing MSB4252.
Evaluate the reference without those properties, as GetTargetFrameworks
does, and drop them from the graph node when every target framework is
RID-agnostic. Gated behind ChangeWave 18.15.

Fixes dotnet#15711

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@AlesProkop
AlesProkop marked this pull request as ready for review December 2, 2026 12:31
Copilot AI balanced review requested due to automatic review settings December 2, 2026 12:31

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.

🟡 Changes recommended

Incorrect Boolean-alias handling can remove required runtime properties during graph prediction, causing configuration mismatches and MSB4252 failures in isolated builds.

2 open issues
What changed in this PR

Aligns isolated static graph builds with runtime project-reference handling so RID-agnostic libraries can build without MSB4252.

Changes:

  • Predicts RID-less reference configurations and reuses discovery evaluations.
  • Limits prediction to eligible single-entry isolated builds behind ChangeWave 18.15.
  • Adds regression coverage and documents the behavior.
File Description
src/​Build/​Graph/​ProjectInterpretation.cs Detects eligible RID-agnostic references.
src/​Build/​Graph/​ProjectGraphOptions.cs Adds an internal prediction option.
src/​Build/​Graph/​ProjectGraph.cs Passes the option to graph construction.
src/​Build/​Graph/​GraphBuilder.cs Restricts entry points and reuses cached evaluations.
src/​Build/​BackEnd/​BuildManager/​BuildManager.cs Enables prediction for eligible isolated builds.
src/​Build.UnitTests/​Graph/​ProjectReferenceTargetsProtocol_Tests.cs Tests isolation, metadata, multitargeting, and entry-point handling.
documentation/​wiki/​ChangeWaves.md Documents the 18.15 behavior and scope.

Review effort: Balanced

&& !enableDynamicPlatformResolution
&& (referenceGlobalProperties.Contains("RuntimeIdentifier") || referenceGlobalProperties.Contains("SelfContained"))
&& (usesCommonReferenceProtocol ??= UsesCommonReferenceProtocol(requesterInstance))
&& !projectReferenceItem.GetMetadataValue("SkipGetTargetFrameworkProperties").Equals("true", StringComparison.OrdinalIgnoreCase)
string isRidAgnostic = project.GetPropertyValue("IsRidAgnostic");
return string.IsNullOrEmpty(isRidAgnostic)
? string.IsNullOrEmpty(project.GetPropertyValue("RuntimeIdentifier")) && string.IsNullOrEmpty(project.GetPropertyValue("RuntimeIdentifiers"))
: !isRidAgnostic.Equals("false", StringComparison.OrdinalIgnoreCase);
- Decline prediction instead of recursing when an inner build still evaluates as an outer build.
- Only predict when the requester's Build dependency chain reaches ResolveProjectReferences.

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

This branch had an error being deployed

1 failed (outdated) deployment
copilot-pat-pool — 95019a8b Deployed Dec 2, 2026 by AlesProkop via conclusion #1266
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.

dotnet build -graph -isolate -r <rid> fails for an app with a class library reference: GetTargetFrameworks is called without RuntimeIdentifier (MSB4252)

2 participants