Skip to content

[fix] Skip MsCoverageReferencedPathMaps target when building with MSBuild graph build/isolation#16032

Draft
nohwnd wants to merge 2 commits into
mainfrom
fix/issue-5190-b5452ca9d9df47cb
Draft

[fix] Skip MsCoverageReferencedPathMaps target when building with MSBuild graph build/isolation#16032
nohwnd wants to merge 2 commits into
mainfrom
fix/issue-5190-b5452ca9d9df47cb

Conversation

@nohwnd
Copy link
Copy Markdown
Member

@nohwnd nohwnd commented May 18, 2026

�� This is an automated fix generated by Issue Repro Triage & Auto-Fix.

Fixes #5190

Root Cause

The MsCoverageReferencedPathMaps target in Microsoft.CodeCoverage.targets calls MSBuild on referenced projects with Properties="TargetFramework=...". This sets a global property on those sub-project invocations, which violates MSBuild's project isolation contract when building with -isolateProjects:true -graphBuild:true.

MSBuild pre-computes the project graph with fixed global properties per project. Any build step that sets new global properties on a project outside the pre-computed graph triggers the isolation error: "global properties set for each project have been altered during the build."

Fix

Add '$(IsGraphBuild)' != 'true' to the conditions on both the <PropertyGroup> and the <Target>. MSBuild sets $(IsGraphBuild) to true when invoked with -graphBuild:true, so this skips the deterministic source mapping step in graph build mode.

This is consistent with the existing $(DisableMsCoverageReferencedPathMaps) escape hatch — the trade-off is that msCoverageSourceRootsMapping_* files are not generated during graph builds, but the build succeeds without isolation violations.

Changes

  • src/package/Microsoft.CodeCoverage/Microsoft.CodeCoverage.targets: Added and '$(IsGraphBuild)' != 'true' condition to MsCoverageReferencedPathMaps target and its associated <PropertyGroup>.

🔍 Triaged by Issue Repro Triage & Auto-Fix 🔍

…olation

Fixes #5190

When MSBuild is invoked with -graphBuild:true and -isolateProjects:true,
the MsCoverageReferencedPathMaps target triggers an isolation violation
by calling MSBuild on referenced projects with Properties= (global
properties). Add IsGraphBuild condition to skip the target in that mode.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 18, 2026 01:38
@nohwnd nohwnd added the bug label May 18, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes MSBuild project isolation failures that occur when building with -graphBuild:true -isolateProjects:true by skipping the MsCoverageReferencedPathMaps target (and its supporting properties) during graph builds, avoiding sub-MSBuild invocations that alter global properties.

Changes:

  • Add and '$(IsGraphBuild)' != 'true' to the conditional PropertyGroup that configures source-root mapping behavior.
  • Add and '$(IsGraphBuild)' != 'true' to the MsCoverageReferencedPathMaps target condition so it is not executed during graph builds.

Copy link
Copy Markdown
Member Author

@nohwnd nohwnd left a comment

Choose a reason for hiding this comment

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

Review Summary

The fix is correct and well-structured for the primary reported scenario (graph build mode). Two notes:

✅ Condition symmetry

Both the <PropertyGroup> (which sets _msCoverageSourceRootTargetName) and the <Target> guard are updated with the same condition. This is consistent — if the PropertyGroup is skipped, the Target is too, preventing any reference to an undefined property.

⚠️ Possible incomplete coverage for pure isolation mode

$(IsGraphBuild) is only set to true when MSBuild is invoked with -graphBuild. The PR title mentions "graph build/isolation", but a user who uses -isolateProjects:true without -graphBuild:true would still hit the same isolation violation — the <MSBuild ... Properties="TargetFramework=..."> sub-project call still sets a global property that violates the isolation contract.

There is no well-known stable MSBuild property for pure isolation mode (analogous to IsGraphBuild), so this may be an acceptable limitation. The existing $(DisableMsCoverageReferencedPathMaps) escape hatch covers this remaining case if users encounter it. Consider documenting this in the PR description or a comment in the .targets file so future maintainers understand the known gap.

✅ No package content changes

No files added or removed from the package; eng/expected-nupkg-file-counts.json does not need updating.


🧠 Reviewed by Expert Code Reviewer

🧠 Reviewed by Expert Code Reviewer 🧠

@nohwnd

This comment has been minimized.

@nohwnd
Copy link
Copy Markdown
Member Author

nohwnd commented May 18, 2026

The latest CI run (build 1424027, 2026-05-18) shows the macOS job was cancelled after ~60 minutes while Windows Release ✅ and Ubuntu ✅ both passed successfully. This appears to be an infrastructure timeout/flake — the change in this PR (Microsoft.CodeCoverage.targets, adding '$(IsGraphBuild)' != 'true' conditions) is a pure MSBuild property check with no platform-specific behavior.

When CI is re-queued, this PR should go green.

🔧 Iterated by PR Iteration Agent 🔧

🔧 Iterated by PR Iteration Agent 🔧

…ojects without -graphBuild)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd
Copy link
Copy Markdown
Member Author

nohwnd commented May 25, 2026

Commit pushed: 4990cd2

🔧 Iterated by PR Iteration Agent 🔧

Copy link
Copy Markdown
Member Author

@nohwnd nohwnd left a comment

Choose a reason for hiding this comment

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

Review Summary

The updated diff addresses the ⚠️ finding from the prior review: a comment has been added to the .targets file documenting why $(IsGraphBuild) is used, the trade-off (no msCoverageSourceRootsMapping_* files in graph build mode), and the $(DisableMsCoverageReferencedPathMaps) escape hatch for users on -isolateProjects without -graphBuild.

✅ All prior findings resolved

  • Condition symmetry between <PropertyGroup> and <Target> remains correct.
  • Comment now documents the known gap for pure isolation mode — future maintainers have the context they need.
  • No package content changes; eng/expected-nupkg-file-counts.json still does not need updating.

No new issues found. The fix is correct and the documentation is clear.


🧠 Reviewed by Expert Code Reviewer

🧠 Reviewed by Expert Code Reviewer 🧠

🧠 Reviewed by Expert Code Reviewer 🧠

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Microsoft.NET.Test.Sdk 17.10 breaks MSBuild isolation

2 participants