Skip to content

Migrate ResolveOverlappingItemGroupConflicts and ResolvePublicOutputConflicts to MT#54355

Merged
AlesProkop merged 7 commits into
dotnet:mainfrom
AlesProkop:migrate-resolveoverlapping-resolvepublishoutput
May 22, 2026
Merged

Migrate ResolveOverlappingItemGroupConflicts and ResolvePublicOutputConflicts to MT#54355
AlesProkop merged 7 commits into
dotnet:mainfrom
AlesProkop:migrate-resolveoverlapping-resolvepublishoutput

Conversation

@AlesProkop

@AlesProkop AlesProkop commented May 18, 2026

Copy link
Copy Markdown
Member

Fixes dotnet/msbuild#13778

Context

ResolveOverlappingItemGroupConflicts performs file existence and version checks through ConflictItem, which previously resolved relative paths against the current working directory. That is unsafe for multithreaded MSBuild execution, where tasks can run on nodes with different working directories.

Changes Made

  • Marked ResolveOverlappingItemGroupConflicts as [MSBuildMultiThreadableTask]
  • Implemented IMultiThreadableTask and routed path resolution through TaskEnvironment
  • Updated ConflictItem to absolutize paths only for file access while preserving original item specs and metadata in outputs
  • Made the file version cache thread-safe by switching to ConcurrentDictionary
  • Added unit coverage for relative HintPath resolution and compatibility when no TaskEnvironment is provided

Testing

  • Added tests covering ResolveOverlappingItemGroupConflicts with relative paths
  • Verified outputs preserve original relative item specs and metadata
  • Verified existing ConflictItem behavior is preserved when not using TaskEnvironment

@AlesProkop AlesProkop self-assigned this May 19, 2026
@AlesProkop AlesProkop changed the title Migrate resolveoverlapping resolvepublishoutput [Draft] Migrate ResolveOverlappingItemGroupConflicts and ResolvePublicOutputConflicts to MT May 19, 2026
@AlesProkop AlesProkop marked this pull request as ready for review May 19, 2026 09:27
Copilot AI review requested due to automatic review settings May 19, 2026 09:27

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 migrates ResolveOverlappingItemGroupConflicts to MSBuild multi-threaded execution by ensuring any on-disk file checks resolve relative paths via TaskEnvironment instead of the process current working directory (fixing the class of issues reported in dotnet/msbuild#13778).

Changes:

  • Marked ResolveOverlappingItemGroupConflicts as [MSBuildMultiThreadableTask], implemented IMultiThreadableTask, and passed TaskEnvironment into conflict item evaluation.
  • Updated ConflictItem to use an absolute path (via TaskEnvironment) only for file I/O while preserving original item specs/metadata for outputs and display.
  • Made the assembly-version cache thread-safe (ConcurrentDictionary) and added unit tests covering relative HintPath resolution and legacy behavior without TaskEnvironment.

Reviewed changes

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

File Description
test/Microsoft.NET.Build.Tasks.Tests/GivenTasksUseAbsolutePaths.cs Adds regression tests for ResolveOverlappingItemGroupConflicts relative path resolution via TaskEnvironment and legacy behavior without it.
src/Tasks/Common/FileUtilities.MetadataReader.cs Switches the shared version cache to ConcurrentDictionary to support multi-threaded task execution safely.
src/Tasks/Common/ConflictResolution/ResolvePublishOutputConflicts.cs Marks ResolveOverlappingItemGroupConflicts as multi-threadable and routes conflict item creation through TaskEnvironment.
src/Tasks/Common/ConflictResolution/ConflictItem.cs Introduces SourcePathForFileAccess to resolve relative paths via TaskEnvironment for file operations while keeping original metadata intact.

@JanProvaznik JanProvaznik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

have you ran the transitive analyzer locally?

Comment thread src/Tasks/Common/ConflictResolution/ConflictItem.cs
Comment thread src/Tasks/Common/ConflictResolution/ConflictItem.cs Outdated
Comment thread src/Tasks/Common/ConflictResolution/ConflictItem.cs Outdated
@AlesProkop

Copy link
Copy Markdown
Member Author

@JanProvaznik Addressed all four comments in the latest commit:

  • Removed the default = null on the ConflictItem ctor parameter; updated the one remaining caller (ResolvePackageFileConflicts) to pass taskEnvironment: null explicitly.
  • Documented why _taskEnvironment is nullable (Platform-item ctor and not-yet-migrated callers like ResolvePackageFileConflicts).
  • Added <inheritdoc/> on ResolveOverlappingItemGroupConflicts.TaskEnvironment.
  • Switched the null check in SourcePathForFileAccess to !string.IsNullOrEmpty(...).

Also ran the ThreadSafeTaskAnalyzer locally against this branch — zero MSBuildTask* diagnostics. Remaining hits in the project are in tasks not migrated yet (ResolvePackageFileConflicts, etc.) and are pre-existing.

@jankratochvilcz jankratochvilcz 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.

Looks great, left a few smaller comments. One iteration and we're there I think :-)

Comment thread src/Tasks/Common/ConflictResolution/ResolvePackageFileConflicts.cs
Comment thread src/Tasks/Common/FileUtilities.MetadataReader.cs
Comment thread test/Microsoft.NET.Build.Tasks.Tests/GivenTasksUseAbsolutePaths.cs Outdated
Comment thread test/Microsoft.NET.Build.Tasks.Tests/GivenTasksUseAbsolutePaths.cs Outdated
Comment thread test/Microsoft.NET.Build.Tasks.Tests/GivenTasksUseAbsolutePaths.cs Outdated
Comment thread test/Microsoft.NET.Build.Tasks.Tests/GivenTasksUseAbsolutePaths.cs
Comment thread test/Microsoft.NET.Build.Tasks.Tests/GivenTasksUseAbsolutePaths.cs Outdated
Comment thread test/Microsoft.NET.Build.Tasks.Tests/GivenTasksUseAbsolutePaths.cs Outdated
Comment thread test/Microsoft.NET.Build.Tasks.Tests/GivenTasksUseAbsolutePaths.cs
Comment thread test/Microsoft.NET.Build.Tasks.Tests/GivenTasksUseAbsolutePaths.cs
Comment thread test/Microsoft.NET.Build.Tasks.Tests/GivenTasksUseAbsolutePaths.cs

@jankratochvilcz jankratochvilcz 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.

Please check out #54355 (comment). Other that that it's merge time 🚀

@AlesProkop AlesProkop enabled auto-merge (squash) May 22, 2026 07:45
@AlesProkop AlesProkop disabled auto-merge May 22, 2026 07:45
@AlesProkop AlesProkop enabled auto-merge (squash) May 22, 2026 07:45
@AlesProkop AlesProkop merged commit 70efca3 into dotnet:main May 22, 2026
25 checks passed
@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.

[Multithreaded] Migrate ResolveOverlappingItemGroupConflicts + ResolvePublishOutputConflicts in SDK

4 participants