Skip to content

Fix parallel-build race condition on RunnableProjects DLL - #54380

Merged
MichaelSimons merged 2 commits into
mainfrom
fix/template-discovery-parallel-build-race
May 21, 2026
Merged

MichaelSimons merged 2 commits into
mainfrom
fix/template-discovery-parallel-build-race

Conversation

@marcpopMSFT

Copy link
Copy Markdown
Member

BuildTestPackages.targets invoked Pack on TemplateSearch.TemplateDiscovery with different global properties (PackageOutputPath, Version), creating a second MSBuild node that cascades to RunnableProjects via ProjectReference. Two concurrent compilations of the same project then contend for the same obj/ output DLL, causing MSB3026 (promoted to error by TreatWarningsAsErrors).

Fix: Remove TemplateSearch.TemplateDiscovery from BuildTestPackages.targets and instead copy the nupkg (already produced via the solution's Pack target) to TestPackagesDir in a post-pack target within the csproj itself.

This is the same pattern used for Authoring.Tasks in commit 3864319.

BuildTestPackages.targets invoked Pack on TemplateSearch.TemplateDiscovery
with different global properties (PackageOutputPath, Version), creating a
second MSBuild node that cascades to RunnableProjects via ProjectReference.
Two concurrent compilations of the same project then contend for the same
obj/ output DLL, causing MSB3026 (promoted to error by TreatWarningsAsErrors).

Fix: Remove TemplateSearch.TemplateDiscovery from BuildTestPackages.targets
and instead copy the nupkg (already produced via the solution's Pack target)
to TestPackagesDir in a post-pack target within the csproj itself.

This is the same pattern used for Authoring.Tasks in commit 3864319.

Co-authored-by: Copilot <[email protected]>
@marcpopMSFT

Copy link
Copy Markdown
Member Author

A codeflow into the VMR failed twice with a build timing issue in a templating component: https://dev.azure.com/dnceng-public/public/_build/results?buildId=1424051&view=results I was pinged in the infra chat and had copilot review the binlog to try to come up with a fix. This is that proposed fix.

@marcpopMSFT
marcpopMSFT requested review from phil-allen-msft and removed request for wtgodbe May 19, 2026 16:29

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

This PR addresses an MSBuild parallel-build race where BuildTestPackages.targets re-packed Microsoft.TemplateSearch.TemplateDiscovery with different global properties, creating concurrent builds that contend over the same obj/ outputs (e.g., RunnableProjects.dll) and can trigger MSB3026.

Changes:

  • Removed Microsoft.TemplateSearch.TemplateDiscovery from BuildTestPackages.targets to avoid re-packing the project with conflicting global properties.
  • Added a post-pack target in Microsoft.TemplateSearch.TemplateDiscovery.csproj to copy its produced .nupkg into $(TestLayoutDir)testpackages/ for test consumption.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
test/Microsoft.NET.TestFramework/BuildTestPackages.targets Stops re-packing TemplateDiscovery via the test-packaging target to prevent parallel build output contention.
src/TemplateEngine/Tools/Microsoft.TemplateSearch.TemplateDiscovery/Microsoft.TemplateSearch.TemplateDiscovery.csproj Copies the already-packed .nupkg into the test packages directory after Pack.

Co-authored-by: Copilot Autofix powered by AI <[email protected]>
@MichaelSimons
MichaelSimons enabled auto-merge (squash) May 20, 2026 13:42
@MichaelSimons

Copy link
Copy Markdown
Member

@marcpopMSFT, I hope you don't mind that I applied a comment wording improvement from copilot and enabled atuo-merge. I've seen this intermittent failure three times in the past 24 hours. Let's get this in 😃

@marcpopMSFT

Copy link
Copy Markdown
Member Author

@marcpopMSFT, I hope you don't mind that I applied a comment wording improvement from copilot and enabled atuo-merge. I've seen this intermittent failure three times in the past 24 hours. Let's get this in 😃

Supportive of this approach. I think we need to be more aggressive about helping each other get our PRs in that are infra or targeted fixes as those should be the easiest to get through. Spend our energy on the complex changes or risky changes.

@MichaelSimons
MichaelSimons merged commit 3a433fa into main May 21, 2026
25 checks passed
@MichaelSimons
MichaelSimons deleted the fix/template-discovery-parallel-build-race branch May 21, 2026 15:09
lewing added a commit to lewing/sdk that referenced this pull request May 26, 2026
PR dotnet#54380 added CopyPackageToTestPackagesDir targets to both
Authoring.Tasks and TemplateDiscovery. A subsequent VMR-only fix
(73010df) added the DotNetBuild guard to Authoring.Tasks but that
hasn't flowed back to SDK main, and TemplateDiscovery never received
the guard at all.

Without this guard, the targets run during VMR source-build where
PackageId/PackageVersion are not set in the outer cross-targeting
evaluation, producing MSB3030 trying to copy '..nupkg'.

This adds the guard to both projects and updates the XML comments.

Co-authored-by: Copilot <[email protected]>
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 11.0-preview6 milestone May 27, 2026
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.

4 participants