Skip to content

Comments

Migrate 5 MSBuild tasks to IMultiThreadableTask (Group 1)#52935

Open
SimaTian wants to merge 3 commits intodotnet:mainfrom
SimaTian:merge-group-1
Open

Migrate 5 MSBuild tasks to IMultiThreadableTask (Group 1)#52935
SimaTian wants to merge 3 commits intodotnet:mainfrom
SimaTian:merge-group-1

Conversation

@SimaTian
Copy link
Member

Squashed merge of 5 MSBuild task migrations to support multithreaded execution.

Stacked on #52909 (multithreading-polyfills).

Migrated Tasks

  • ResolvePackageDependencies
  • GetAssemblyAttributes
  • GenerateToolsSettingsFile
  • GenerateClsidMap
  • GenerateRuntimeConfigurationFiles

Changes (13 files)

Each task receives:

  • [MSBuildMultiThreadableTask] attribute
  • IMultiThreadableTask interface implementation
  • TaskEnvironment property
  • Path absolutization for File/Directory/FileStream operations

Includes multithreading unit tests for each task.

Test Results

233 passed, 11 failed (pre-existing redist.csproj failures, unrelated).

Copilot AI review requested due to automatic review settings February 10, 2026 13:14
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 + TaskEnvironment to 5 tasks and route file/path operations through TaskEnvironment.
  • 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

Copy link
Member Author

@SimaTian SimaTian left a comment

Choose a reason for hiding this comment

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

Addressed all review comments:

  1. 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.

  2. 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.

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
Copy link
Member Author

@SimaTian SimaTian left a comment

Choose a reason for hiding this comment

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

This is as reasonable as I could force copilot to make it.

SimaTian and others added 2 commits February 24, 2026 10:45
- 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>
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