Skip to content

Comments

Add IMultiThreadableTask and TaskEnvironment polyfills for multithrea…#52909

Merged
baronfel merged 5 commits intodotnet:mainfrom
SimaTian:multithreading-polyfills
Feb 10, 2026
Merged

Add IMultiThreadableTask and TaskEnvironment polyfills for multithrea…#52909
baronfel merged 5 commits intodotnet:mainfrom
SimaTian:multithreading-polyfills

Conversation

@SimaTian
Copy link
Member

@SimaTian SimaTian commented Feb 9, 2026

…ding support

  • Add polyfill files in src/Tasks/Common/ (gated with #if NETFRAMEWORK):
    • IMultiThreadableTask.cs: Interface declaring thread-safe task capability
    • TaskEnvironment.cs: Sealed class providing thread-safe environment access
    • AbsolutePath.cs: Readonly struct for absolute path representation
    • ITaskEnvironmentDriver.cs: Internal driver interface for TaskEnvironment
    • ProcessTaskEnvironmentDriver.cs: Driver wrapping real process state
  • Add TaskEnvironmentHelper.cs in test project (not gated):
    • Uses DispatchProxy + reflection to construct TaskEnvironment for tests
    • Supports custom ProjectDirectory independent from process CWD
  • Add TaskEnvironmentHelperTests.cs with smoke tests
  • Existing attribute polyfill (MSBuildMultiThreadableTaskAttribute.cs) unchanged
  • All existing tests pass (214 passed, 11 pre-existing failures)

…ding support

- Add polyfill files in src/Tasks/Common/ (gated with #if NETFRAMEWORK):
  - IMultiThreadableTask.cs: Interface declaring thread-safe task capability
  - TaskEnvironment.cs: Sealed class providing thread-safe environment access
  - AbsolutePath.cs: Readonly struct for absolute path representation
  - ITaskEnvironmentDriver.cs: Internal driver interface for TaskEnvironment
  - ProcessTaskEnvironmentDriver.cs: Driver wrapping real process state
- Add TaskEnvironmentHelper.cs in test project (not gated):
  - Uses DispatchProxy + reflection to construct TaskEnvironment for tests
  - Supports custom ProjectDirectory independent from process CWD
- Add TaskEnvironmentHelperTests.cs with smoke tests
- Existing attribute polyfill (MSBuildMultiThreadableTaskAttribute.cs) unchanged
- All existing tests pass (214 passed, 11 pre-existing failures)
Copilot AI review requested due to automatic review settings February 9, 2026 14:56
@SimaTian
Copy link
Member Author

SimaTian commented Feb 9, 2026

These are to be removed after MSBuild Frameworks dependencies correctly include them (or maybe together with the reference update if they cause a conflict)
However without these I can't proceed with the task migration for non-trivial cases.

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

This PR adds .NET Framework–gated polyfills of MSBuild’s multithreaded task surface area (TaskEnvironment, AbsolutePath, driver interfaces, and IMultiThreadableTask) so SDK tasks can compile/run against older MSBuild versions, and introduces a test helper + smoke tests to construct/use TaskEnvironment from the test project.

Changes:

  • Add #if NETFRAMEWORK polyfills in src/Tasks/Common/ for IMultiThreadableTask, TaskEnvironment, AbsolutePath, and the task-environment driver abstractions/implementation.
  • Add TaskEnvironmentHelper in the unit test project to construct TaskEnvironment via DispatchProxy/reflection.
  • Add smoke tests validating ProjectDirectory and GetAbsolutePath behavior.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/Tasks/Common/IMultiThreadableTask.cs NETFRAMEWORK polyfill for MSBuild multithreadable task interface.
src/Tasks/Common/TaskEnvironment.cs NETFRAMEWORK polyfill wrapper delegating to ITaskEnvironmentDriver.
src/Tasks/Common/ITaskEnvironmentDriver.cs NETFRAMEWORK polyfill for internal driver interface.
src/Tasks/Common/ProcessTaskEnvironmentDriver.cs NETFRAMEWORK driver implementation using process state.
src/Tasks/Common/AbsolutePath.cs NETFRAMEWORK polyfill for absolute-path representation/comparison.
src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/TaskEnvironmentHelper.cs Test helper to construct TaskEnvironment via reflection/DispatchProxy.
src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/TaskEnvironmentHelperTests.cs Smoke tests for TaskEnvironmentHelper.

…lidation, improve reflection safety

- ProcessTaskEnvironmentDriver: maintain per-instance environment dictionary
  instead of mutating global process state (reviews on lines 78, 99)
- AbsolutePath.ValidatePath: use IsPathFullyQualified to reject drive-relative
  paths like 'C:foo' on Windows (review on line 82)
- TaskEnvironmentHelper: select constructor by parameter type instead of
  ctor[0] index (review on line 56)
- TestDriverProxy: scope environment state to instance dictionary instead of
  modifying process environment (review on line 134)
- TestDriverProxy: throw NotSupportedException for unrecognized method names
  instead of returning null (review on line 90)
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

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

SimaTian and others added 2 commits February 10, 2026 09:17
…hecks

In GetAbsolutePath, use new AbsolutePath(path) instead of
new AbsolutePath(path, ignoreRootedCheck: true) to ensure drive-relative
paths like 'C:foo' are properly rejected by the fully-qualified validation.
- Make TaskEnvironment and AbsolutePath public (fixes CS0053 inconsistent
  accessibility when tasks declare public TaskEnvironment property)
- Use EnvironmentVariables instead of Environment on ProcessStartInfo
  (Environment property not available on net472)
- Fix IsPathFullyQualified to reject drive-relative paths like \foo on
  Windows (only UNC/drive-rooted/extended paths are fully qualified)
@baronfel baronfel merged commit b30945d into dotnet:main Feb 10, 2026
23 of 25 checks passed
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.

2 participants