Migrate 5 MSBuild tasks to IMultiThreadableTask (Group 1)#52935
Migrate 5 MSBuild tasks to IMultiThreadableTask (Group 1)#52935SimaTian wants to merge 3 commits intodotnet:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Migrates a first group of MSBuild tasks in Microsoft.NET.Build.Tasks to support MSBuild’s multi-threaded task execution model by implementing IMultiThreadableTask, using TaskEnvironment for path resolution, and adding unit tests validating the new behavior.
Changes:
- Add
[MSBuildMultiThreadableTask]+IMultiThreadableTask+TaskEnvironmentto 5 tasks and route file/path operations throughTaskEnvironment. - Add new unit tests (and a test helper) to validate interface/attribute presence and TaskEnvironment-based path resolution.
- Add .NET Framework polyfills for
IMultiThreadableTask,TaskEnvironment,AbsolutePath, and supporting driver types.
Reviewed changes
Copilot reviewed 20 out of 20 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageDependencies.cs | Implements multi-threadable task + uses TaskEnvironment for project-relative path resolution |
| src/Tasks/Microsoft.NET.Build.Tasks/GetAssemblyAttributes.cs | Implements multi-threadable task + uses TaskEnvironment to resolve template path |
| src/Tasks/Microsoft.NET.Build.Tasks/GenerateToolsSettingsFile.cs | Implements multi-threadable task + uses TaskEnvironment to resolve output path (already has NETFRAMEWORK split) |
| src/Tasks/Microsoft.NET.Build.Tasks/GenerateClsidMap.cs | Implements multi-threadable task + uses TaskEnvironment to resolve input/output file paths |
| src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs | Implements multi-threadable task + uses TaskEnvironment for lockfile and runtimeconfig IO paths |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/TaskEnvironmentHelper.cs | Adds reflection/DispatchProxy helper to create TaskEnvironment instances for tests |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/TaskEnvironmentHelperTests.cs | Adds tests validating TaskEnvironmentHelper behavior |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/Microsoft.NET.Build.Tasks.UnitTests.csproj | Adds Microsoft.NET.HostModel reference needed for executing tasks in tests |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAResolvePackageDependenciesTask.cs | Updates existing tests to provide TaskEnvironment and use full project path |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAResolvePackageDependenciesMultiThreading.cs | Adds multi-threading-focused tests for ResolvePackageDependencies |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAGetAssemblyAttributesMultiThreading.cs | Adds multi-threading-focused tests for GetAssemblyAttributes |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAGenerateToolsSettingsFileMultiThreading.cs | Adds multi-threading-focused tests for GenerateToolsSettingsFile |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAGenerateRuntimeConfigurationFiles.cs | Ensures TaskEnvironment is present for test subclass execution |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAGenerateRuntimeConfigMultiThreading.cs | Adds multi-threading-focused tests for GenerateRuntimeConfigurationFiles |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAGenerateClsidMapMultiThreading.cs | Adds multi-threading-focused tests for GenerateClsidMap |
| src/Tasks/Common/IMultiThreadableTask.cs | Adds NETFRAMEWORK polyfill for IMultiThreadableTask |
| src/Tasks/Common/TaskEnvironment.cs | Adds NETFRAMEWORK polyfill for TaskEnvironment |
| src/Tasks/Common/AbsolutePath.cs | Adds NETFRAMEWORK polyfill for AbsolutePath |
| src/Tasks/Common/ITaskEnvironmentDriver.cs | Adds NETFRAMEWORK polyfill for ITaskEnvironmentDriver |
| src/Tasks/Common/ProcessTaskEnvironmentDriver.cs | Adds NETFRAMEWORK driver implementation used by TaskEnvironment polyfill |
src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageDependencies.cs
Outdated
Show resolved
Hide resolved
src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs
Show resolved
Hide resolved
03c639d to
ae4c7f9
Compare
SimaTian
left a comment
There was a problem hiding this comment.
Addressed all review comments:
-
TaskEnvironment/AbsolutePath accessibility (4 comments): Fixed in the polyfills PR (#52909) by making both types \public\ instead of \internal. This eliminates the need for #if NETFRAMEWORK\ conditional compilation in every task file.
-
Path.GetDirectoryName(ProjectPath) null check in ResolvePackageDependencies: Added fallback to \TaskEnvironment.ProjectDirectory\ when the directory name is null/empty.
All branches have been rebased on the updated polyfills and force-pushed.
ae4c7f9 to
478deed
Compare
src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageDependencies.cs
Outdated
Show resolved
Hide resolved
src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAGenerateClsidMapMultiThreading.cs
Outdated
Show resolved
Hide resolved
src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAGenerateClsidMapMultiThreading.cs
Outdated
Show resolved
Hide resolved
src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs
Show resolved
Hide resolved
src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs
Show resolved
Hide resolved
src/Tasks/Microsoft.NET.Build.Tasks/GenerateRuntimeConfigurationFiles.cs
Show resolved
Hide resolved
6b728a6 to
a59da22
Compare
ad5f1e1 to
56d1660
Compare
Migrate GenerateRuntimeConfigurationFiles, GenerateToolsSettingsFile, GetAssemblyAttributes, ResolvePackageDependencies, and GenerateClsidMap to use TaskEnvironment for path resolution instead of Environment.CurrentDirectory. - Add [MSBuildMultiThreadableTask] attribute and IMultiThreadableTask - Use TaskEnvironment.GetAbsolutePath for relative path resolution - Add TaskTestEnvironment test infrastructure - Add multithreading tests for path resolution and parity - Remove redundant attribute-existence-only tests
56d1660 to
3796e46
Compare
SimaTian
left a comment
There was a problem hiding this comment.
This is as reasonable as I could force copilot to make it.
- Replace List<TestPackageReference> with ConcurrentBag for thread-safe concurrent writes - Add missing .Add() call inside Parallel.ForEach lambda Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Add TaskEnvironmentDefaults.cs for NETFRAMEWORK lazy-init fallback - Apply lazy-init pattern to GenerateClsidMap, GenerateRuntimeConfigurationFiles, GenerateToolsSettingsFile, GetAssemblyAttributes, ResolvePackageDependencies Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Squashed merge of 5 MSBuild task migrations to support multithreaded execution.
Stacked on #52909 (multithreading-polyfills).
Migrated Tasks
Changes (13 files)
Each task receives:
Includes multithreading unit tests for each task.
Test Results
233 passed, 11 failed (pre-existing redist.csproj failures, unrelated).