Skip to content

Normalize project paths in Arcade Build.proj restore exclude - #6867

Merged
akoeplinger merged 1 commit into
dotnet:mainfrom
akoeplinger:fix/arcade-restore-path-normalization
May 27, 2026
Merged

akoeplinger merged 1 commit into
dotnet:mainfrom
akoeplinger:fix/arcade-restore-path-normalization

Conversation

@akoeplinger

Copy link
Copy Markdown
Member

Problem

The Exclude="@(_ProjectToRestoreWithNuGet)" in Microsoft.DotNet.Arcade.Sdk/toolset/Build.proj does a literal item-spec comparison. When a caller passes a project path with redundant separators (e.g. a build script that does $repo_root/foo while $repo_root already ends in /, producing /repo//foo), the path differs from the NuGet-normalized form returned by _IsProjectRestoreSupported. The Exclude misses, the project ends up in _ProjectToRestore twice, and MSBuild kicks off two parallel Restore invocations against the same graph.

Both restores then race to commit the same project.assets.json via File.Move(overwrite: true), which is non-atomic on Linux, producing the flaky:

error : The file '.../obj/<project>/project.assets.json' already exists.
   at System.IO.FileSystem.LinkOrCopyFile(...)
   at NuGet.Commands.RestoreResult.CommitAssetsFileAsync(...)

This was observed in a VMR build of src/fsharp where eng/build.sh passes $repo_root/src/Microsoft.FSharp.Compiler/Microsoft.FSharp.Compiler.fsproj (with $repo_root already trailing-slashed by eng/common/tools.sh), producing a double slash. Two RestoreTask invocations both started within ~28 ms of each other and raced on FSharp.DependencyManager.Nuget's assets file.

Fix

Project both sides of the Exclude through %(FullPath), which applies MSBuild's path normalization (collapses //, resolves ./.., normalizes separators). The comparison then no longer depends on the caller passing a canonical path, protecting every Arcade-using repo from this class of flaky parallel-restore failure.

<_ProjectToRestore Include="@(ProjectToBuild->'%(FullPath)')" Exclude="@(_ProjectToRestoreWithNuGet->'%(FullPath)')" />

No behavior change for callers that already pass canonical paths.

The Exclude="@(_ProjectToRestoreWithNuGet)" was a literal item-spec
compare, so user-supplied paths with redundant separators (e.g.
'/repo//src/foo.csproj') would not match the NuGet-normalized paths
returned by _IsProjectRestoreSupported. The project then ended up in
_ProjectToRestore twice and was restored in parallel, racing on
project.assets.json and producing the flaky:

    error : The file '.../project.assets.json' already exists.

Project the items through %(FullPath) on both sides so the comparison
is path-form-independent.

Co-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings May 27, 2026 14:35
@dotnet-policy-service
dotnet-policy-service Bot requested a review from a team May 27, 2026 14:35

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 hardens Arcade’s toolset restore orchestration by normalizing project paths before performing MSBuild item-spec exclusion, preventing the same project from being restored twice (and racing on project.assets.json) when callers pass non-canonical paths (e.g., redundant separators).

Changes:

  • Normalize both @(ProjectToBuild) and @(_ProjectToRestoreWithNuGet) through %(FullPath) when computing _ProjectToRestore.
  • Expand the inline comment to document the underlying path-comparison pitfall and the parallel-restore race it can trigger.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@akoeplinger
akoeplinger merged commit 0f785fd into dotnet:main May 27, 2026
9 of 11 checks passed
@akoeplinger
akoeplinger deleted the fix/arcade-restore-path-normalization branch May 27, 2026 17:30
@akoeplinger

Copy link
Copy Markdown
Member Author

/backport to release/10.0.1xx

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/10.0.1xx (link to workflow run)

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.

3 participants