Fix intermittent build failure from duplicate graph builds of TemplateEngine projects#54317
Merged
MichaelSimons merged 4 commits intoMay 18, 2026
Conversation
…eEngine projects Authoring.Tasks.csproj publishes itself during pack (DependsOnTargets=Publish), which sets PublishDir as a global property. This leaked through to its three ProjectReference items, creating duplicate graph nodes in /graph mode that built the same projects to the same output path concurrently, causing MSB3894 file lock errors. Add GlobalPropertiesToRemove=PublishDir to the three references, matching the pattern used by dotnet.csproj and other src/Cli/ projects. Fixes dotnet#54020 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses intermittent CI build failures in static graph builds caused by the PublishDir global property flowing into ProjectReference builds, creating duplicate graph nodes that concurrently write to the same output paths (leading to MSB3894/MSB3026 file-lock errors).
Changes:
- Prevent
PublishDirfrom propagating to TemplateEngine project references during Publish by addingGlobalPropertiesToRemove="PublishDir"to the relevantProjectReferenceitems.
This was referenced May 15, 2026
Open
NikolaMilosavljevic
approved these changes
May 18, 2026
Member
Author
|
/ba-g - failures appear unrelated to changes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix intermittent build failure caused by duplicate graph builds of TemplateEngine projects
Fixes #54020
Problem
The
TestBuild: linux (x64)andTestBuild: linux (arm64)CI legs intermittently fail with MSB3894/MSB3026 errors:This has been a recurring issue tracked as a Known Build Error with
BuildRetry: trueas the only mitigation.Root Cause Analysis
The SDK build uses
/graphmode (set ineng/build.sh). In static graph builds, MSBuild creates a separate graph node for each unique combination of (project path, global properties). Two nodes with different global properties but the same output path will be scheduled concurrently, causing file lock races.How the duplicate builds arise
Microsoft.TemplateEngine.Authoring.Tasks.csprojis a packable MSBuild task project that publishes itself during pack via:When the
Publishtarget runs, MSBuild setsPublishDiras a global property. This property then leaks through to the project's threeProjectReferenceitems because they did not specifyGlobalPropertiesToRemove="PublishDir":This creates two distinct graph nodes for each referenced project:
PublishDirset?artifacts/bin/.../net10.0/artifacts/bin/.../net10.0/(same!)Because
PublishDirdoesn't affect the referenced project's output directory, both nodes write to the same path concurrently. When one MSBuild node's compiler holds a lock on the obj DLL while the other node'sCopyFilesToOutputDirectorytask tries to read it, the build fails.Evidence from the build log
The build log for build 1421188 confirms the duplicate builds — the same project produces output multiple times for the same TFM:
The same pattern affects
Microsoft.TemplateEngine.Edgeand other transitive dependencies ofAuthoring.Tasks.Why
MSBUILDALWAYSRETRY=truedoesn't helpThe retry mechanism fires (the log shows "Beginning retry 1 in 1000ms") and sometimes succeeds. But because the contention comes from a concurrent build of the same project — not a transient file system hiccup — the lock can persist through all retry attempts.
Fix
Added
GlobalPropertiesToRemove="PublishDir"to the threeProjectReferenceitems inMicrosoft.TemplateEngine.Authoring.Tasks.csproj. This preventsPublishDirfrom propagating to referenced projects during Publish, ensuring each project gets a single graph node per TFM rather than duplicate nodes that race against each other.This matches the pattern already established by
src/Cli/dotnet/dotnet.csprojand other projects in thesrc/Cli/directory, which consistently useGlobalPropertiesToRemove="PublishDir"on all their project references for exactly this reason.