Migrate 5 MSBuild tasks to IMultiThreadableTask (Group 3: Package Assets & App Host)#52938
Migrate 5 MSBuild tasks to IMultiThreadableTask (Group 3: Package Assets & App Host)#52938SimaTian wants to merge 2 commits intodotnet:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Migrates a set of SDK MSBuild tasks to support MSBuild multithreaded execution by marking them multi-threadable and (where needed) implementing IMultiThreadableTask with TaskEnvironment-based absolute path resolution, plus adds supporting polyfills/tests.
Changes:
- Mark tasks as multi-threadable (
[MSBuildMultiThreadableTask]) and migrate key tasks toIMultiThreadableTaskwithTaskEnvironment.GetAbsolutePath(...). - Add
TaskEnvironmenttest helper + new multithreading-focused unit tests for the migrated tasks. - Add .NET Framework-only polyfills for
IMultiThreadableTask,TaskEnvironment,AbsolutePath, and drivers.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Tasks/Microsoft.NET.Build.Tasks/ResolvePackageAssets.cs | Implements IMultiThreadableTask, adds TaskEnvironment, uses it to absolutize cache/assets paths. |
| src/Tasks/Microsoft.NET.Build.Tasks/CreateAppHost.cs | Implements IMultiThreadableTask, adds TaskEnvironment, absolutizes apphost/source/destination/resource paths. |
| src/Tasks/Microsoft.NET.Build.Tasks/CheckForTargetInAssetsFile.cs | Marks task as multi-threadable via attribute. |
| src/Tasks/Microsoft.NET.Build.Tasks/AllowEmptyTelemetry.cs | Marks task as multi-threadable via attribute. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/TaskEnvironmentHelperTests.cs | Adds tests validating TaskEnvironmentHelper behavior. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/TaskEnvironmentHelper.cs | Adds helper for constructing TaskEnvironment in unit tests via proxy/reflection. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/Microsoft.NET.Build.Tasks.UnitTests.csproj | Adds package reference needed by new/updated tests. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAResolvePackageAssetsTask.cs | Updates existing tests to provide TaskEnvironment. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAResolvePackageAssetsMultiThreading.cs | Adds multithreading/migration verification tests for ResolvePackageAssets. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenACreateAppHostMultiThreading.cs | Adds multithreading/migration verification tests for CreateAppHost. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenACheckForTargetInAssetsFileMultiThreading.cs | Adds attribute-presence test for multi-threading marker. |
| src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/GivenAAllowEmptyTelemetryMultiThreading.cs | Adds attribute-presence test for multi-threading marker. |
| src/Tasks/Microsoft.NET.Build.Extensions.Tasks/GetDependsOnNETStandard.cs | Implements IMultiThreadableTask, adds TaskEnvironment, absolutizes reference paths. |
| src/Tasks/Microsoft.NET.Build.Extensions.Tasks.UnitTests/Microsoft.NET.Build.Extensions.Tasks.UnitTests.csproj | Links TaskEnvironmentHelper into extensions task tests. |
| src/Tasks/Microsoft.NET.Build.Extensions.Tasks.UnitTests/GivenAGetDependsOnNETStandardTask.cs | Updates existing tests to provide TaskEnvironment. |
| src/Tasks/Microsoft.NET.Build.Extensions.Tasks.UnitTests/GivenAGetDependsOnNETStandardMultiThreading.cs | Adds multithreading/migration verification tests for GetDependsOnNETStandard. |
| src/Tasks/Common/TaskEnvironment.cs | Adds .NET Framework polyfill for TaskEnvironment. |
| src/Tasks/Common/ProcessTaskEnvironmentDriver.cs | Adds .NET Framework polyfill driver for environment/path resolution. |
| src/Tasks/Common/ITaskEnvironmentDriver.cs | Adds .NET Framework polyfill interface for TaskEnvironment drivers. |
| src/Tasks/Common/IMultiThreadableTask.cs | Adds .NET Framework polyfill for IMultiThreadableTask. |
| src/Tasks/Common/AbsolutePath.cs | Adds .NET Framework polyfill for AbsolutePath. |
8791b9d to
0a5aad7
Compare
SimaTian
left a comment
There was a problem hiding this comment.
Addressed review comments:
- ProcessStartInfo.Environment: Fixed in polyfills PR (#52909) - now uses
EnvironmentVariableswhich is available on net472. - TaskEnvironment null validation: By design, MSBuild always populates TaskEnvironment before task execution. Adding explicit null checks would add defensive code that never executes in practice. The
= null!annotation is not used because these files have#nullable disable. If the team prefers explicit validation, happy to add it. - CreateAppHost TaskEnvironment: Same as above - MSBuild guarantees population.
- AbsolutePath.IsPathFullyQualified: Fixed in polyfills PR (#52909) - now correctly rejects drive-relative paths like
\fooon Windows. Only UNC, drive-rooted, and extended paths are accepted as fully qualified.
All branches rebased on updated polyfills and force-pushed.
src/Tasks/Microsoft.NET.Build.Extensions.Tasks/GetDependsOnNETStandard.cs
Show resolved
Hide resolved
99300c3 to
bfe2cb6
Compare
Migrate AllowEmptyTelemetry, CheckForTargetInAssetsFile, CreateAppHost, ResolvePackageAssets, and GetDependsOnNETStandard to use TaskEnvironment for path resolution. - Add [MSBuildMultiThreadableTask] attribute and IMultiThreadableTask - Use TaskEnvironment.GetAbsolutePath for relative path resolution - Add TaskTestEnvironment test infrastructure - Add multithreading and absolute-path tests
bfe2cb6 to
e80e1bc
Compare
These assertions are redundant - the interface implementation is already verified by the compiler. Attribute-presence tests are sufficient. Co-authored-by: Copilot <[email protected]>
|
@dotnet/domestic-cat Can you suggest how to best work around that please? These changes are something we need as a part of making MSBuild Multithreading work. (other merge groups will most likely be affected as well, so let's just use this one as a representative sample) |
Migrate 5 MSBuild tasks to IMultiThreadableTask (Group 3: Package Assets & App Host)
Context
This PR migrates 5 MSBuild tasks to support multithreaded execution by implementing
IMultiThreadableTask.Migrated Tasks
AssetsFilePathandProjectAssetsCacheFileviaTaskEnvironment.GetAbsolutePath();LockFileCacheuses absolutized pathsAppHostSourcePathandAppHostDestinationDirectoryPathviaTaskEnvironment.GetAbsolutePath();#if NETFRAMEWORKguard on polyfillTaskEnvironment.GetAbsolutePath(); separate Extensions.Tasks projectLockFileCacheChanges Per Task
Each task receives:
[MSBuildMultiThreadableTask]attributeIMultiThreadableTaskinterface implementation (Pattern B tasks)TaskEnvironmentproperty (Pattern B tasks)TaskEnvironment.GetAbsolutePath())New Test Files
GivenAResolvePackageAssetsMultiThreading.csGivenACreateAppHostMultiThreading.csGivenAGetDependsOnNETStandardMultiThreading.cs(in Extensions.Tasks.UnitTests)GivenAAllowEmptyTelemetryMultiThreading.csGivenACheckForTargetInAssetsFileMultiThreading.csOther Modified Files
GivenAResolvePackageAssetsTask.cs— existing tests updated to provideTaskEnvironmentGivenAGetDependsOnNETStandardTask.cs— existing tests updated to provideTaskEnvironmentMicrosoft.NET.Build.Tasks.UnitTests.csproj—TaskEnvironmentHelpercompile link addedMicrosoft.NET.Build.Extensions.Tasks.UnitTests.csproj—TaskEnvironmentHelpercompile link addedNote on GetDependsOnNETStandard
This task is in the
Microsoft.NET.Build.Extensions.Tasksproject (separate from the mainBuild.Tasksproject). Its test is inExtensions.Tasks.UnitTests. No conflicts with other tasks in this group.Testing
ToolsetInfoenvironment failures, unrelated)