Repository navigation
Fix intermittent circular dependency in sharedfx.targets (MSB4006) - #6697
Conversation
Add differentiating global properties to self-referencing MSBuild calls in _AddFilesToNuGetPackage and GetFilesToPublish targets. Without these, when the MSBuild scheduler builds the same sfxproj concurrently with identical global properties, it detects a false circular dependency involving _AddFilesToNuGetPackage or GetFilesToPublish. The _AddFilesToNuGetPackage target was observed causing MSB4006 in dotnet/aspnetcore CI (build 1426800). A previous workaround in aspnetcore (PR dotnet/aspnetcore#65667) addressed GetFilesToPublish from the caller side; this fix addresses both targets at the source. See dotnet/msbuild#13599 Co-authored-by: Copilot <[email protected]>
The _PublishingToLayout workaround (dotnet/aspnetcore#65667) is no longer needed now that sharedfx.targets adds differentiating properties to its self-referencing MSBuild calls directly. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Pull request overview
Fixes an intermittent MSBuild scheduler false-positive circular dependency (MSB4006) triggered by self-referencing MSBuild Projects="$(MSBuildProjectFullPath)" calls in the SharedFramework SDK’s targets, and removes an aspnetcore caller-side workaround now made unnecessary by the SDK-side fix.
Changes:
- Add dummy global properties to the nested self-builds in
sharedfx.targetsso they always differ from the parent build configuration. - Remove
_PublishingToLayout=truefrom the aspnetcore sharedfx publish-to-layout nested call (the prior workaround forGetFilesToPublish).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/aspnetcore/src/Framework/App.Runtime/src/Microsoft.AspNetCore.App.Runtime.sfxproj | Removes the _PublishingToLayout workaround property from a nested publish call now that the SDK target itself differentiates configurations. |
| src/arcade/src/Microsoft.DotNet.SharedFramework.Sdk/targets/sharedfx.targets | Adds _GettingFilesForPackage / _GettingFilesForPublish properties to nested self-MSBuild calls to prevent intermittent MSB4006 circular dependency detection. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Needs a fix:
Looking |
The Microsoft.NETCore.App.Runtime.CoreCLR.sfxproj produces a composite R2R Mach-O image named Microsoft.NETCore.App.Runtime.CoreCLR.r2r.dylib on Apple mobile platforms, but the platform manifest only listed Microsoft.NETCore.App.r2r.dylib (from Microsoft.NETCore.App.Mono.sfxproj). This was a latent bug previously hidden because _AddFilesToNuGetPackage's nested MSBuild call had identical global properties to the parent build, causing MSBuild to reuse cached results and skip fresh validation. The sharedfx.targets fix in this PR makes the nested call use distinct global properties, which correctly triggers _ValidateAllFilesInTemplatedPlatformManifest and surfaces this missing manifest entry. Co-authored-by: Copilot <[email protected]>
|
Pushed 7080fe5 - CC @radekdoulik, @hoyosjs - see the "Problem 2" section in the PR description |
|
I think this PR has introduced a new problem. When building the VMR, I get: Claude says: Before the PRBoth nested calls had identical global properties to their parent. MSBuild's scheduler sees two build requests for the same project with the same global properties and treats them as the same build instance — it deduplicates them, serializes them, or serves a cached result. Only one instance of The downside: the deduplication/caching interaction occasionally triggered MSB4006 (false-positive "circular dependency" from MSBuild's scheduler when two nodes raced to claim the same project). This was the bug the PR was fixing. It was intermittent. After the PRThe two nested calls now have different global properties. MSBuild's scheduler treats them as entirely separate project instances — they get separate cache entries, and can be scheduled on separate worker nodes concurrently. Both execute The MSB4006 is gone. In its place is a file-lock crash. This failure is more deterministic — it happens whenever the scheduler places the two instances on concurrent nodes, which at |
Reverts the _GettingFilesForPackage/_GettingFilesForPublish property additions in sharedfx.targets and restores _PublishingToLayout in aspnetcore sfxproj. These changes caused MSBuild to schedule the nested calls as separate project instances, leading to concurrent writes to the same deps.json file — producing deterministic file-lock failures on all main rolling builds (6/6 failed in 24h). Keeps the PlatformManifestFileEntry addition for Microsoft.NETCore.App.Runtime.CoreCLR.r2r.dylib (real bug fix). The original MSB4006 intermittent circular dependency is tracked at dotnet/msbuild#13599 and needs a fix that doesn't create concurrent project instances. Partial revert of dotnet#6697. Co-authored-by: Copilot <[email protected]>
Summary
Fixes an intermittent
MSB4006: There is a circular dependency in the target dependency graphbuild failure in shared framework projects, and fixes a latent platform manifest bug exposed by the fix.Problem 1: Circular dependency (MSB4006)
sharedfx.targetscontains self-referencing<MSBuild Projects="$(MSBuildProjectFullPath)">calls in_AddFilesToNuGetPackageandGetFilesToPublish. When these nested calls produce identical global properties to the parent build, the MSBuild scheduler treats them as the same build and detects a false circular dependency._AddFilesToNuGetPackage(line 540) usesRemoveProperties="NoBuild", but whenNoBuildisn't set in the outer build, removing it is a no-op — the nested call has identical global properties to the parent.Fix
Add differentiating dummy properties (
_GettingFilesForPackage=true,_GettingFilesForPublish=true) to the nested MSBuild calls so they always have distinct global property sets from the parent build.This is the same pattern used in the workaround at dotnet/aspnetcore#65667 (which added
_PublishingToLayout=trueto the caller side forGetFilesToPublish). This PR fixes both targets at the source in arcade and removes the aspnetcore workaround.Evidence
sharedfx.targets(540,5): error MSB4006: There is a circular dependency in the target dependency graph involving target "_AddFilesToNuGetPackage"Problem 2: Missing platform manifest entry (exposed by fix)
With the circular dependency fix, the nested MSBuild call in
_AddFilesToNuGetPackagenow correctly runs as a distinct build instead of reusing cached results from the parent. This causes_ValidateAllFilesInTemplatedPlatformManifestto evaluate freshly and catch a pre-existing bug:Microsoft.NETCore.App.Runtime.CoreCLR.r2r.dylib(the composite R2R Mach-O image produced byMicrosoft.NETCore.App.Runtime.CoreCLR.sfxprojon Apple mobile platforms) was missing from thePlatformManifestFileEntrylist.The manifest already had
Microsoft.NETCore.App.r2r.dylib(from the Mono sfxproj), but not the CoreCLR variant. This bug was latent — previously hidden because MSBuild reused the parent build's already-evaluated targets, skipping fresh validation.Fix
Add
Microsoft.NETCore.App.Runtime.CoreCLR.r2r.dylibto thePlatformManifestFileEntrylist insrc/runtime/src/installer/pkg/sfx/Microsoft.NETCore.App/Directory.Build.props.Changes
_GettingFilesForPackageand_GettingFilesForPublishdifferentiating properties to nested MSBuild calls in sharedfx.targets_PublishingToLayoutworkaround from sfxproj (no longer needed)Microsoft.NETCore.App.Runtime.CoreCLR.r2r.dylibplatform manifest entry