Add IMultiThreadableTask and TaskEnvironment polyfills for multithrea…#52909
Merged
baronfel merged 5 commits intodotnet:mainfrom Feb 10, 2026
Merged
Add IMultiThreadableTask and TaskEnvironment polyfills for multithrea…#52909baronfel merged 5 commits intodotnet:mainfrom
baronfel merged 5 commits intodotnet:mainfrom
Conversation
…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)
Member
Author
|
These are to be removed after MSBuild Frameworks dependencies correctly include them (or maybe together with the reference update if they cause a conflict) |
Contributor
There was a problem hiding this comment.
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 NETFRAMEWORKpolyfills insrc/Tasks/Common/forIMultiThreadableTask,TaskEnvironment,AbsolutePath, and the task-environment driver abstractions/implementation. - Add
TaskEnvironmentHelperin the unit test project to constructTaskEnvironmentvia DispatchProxy/reflection. - Add smoke tests validating
ProjectDirectoryandGetAbsolutePathbehavior.
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. |
src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/TaskEnvironmentHelper.cs
Outdated
Show resolved
Hide resolved
src/Tasks/Microsoft.NET.Build.Tasks.UnitTests/TaskEnvironmentHelper.cs
Outdated
Show resolved
Hide resolved
…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)
baronfel
approved these changes
Feb 9, 2026
This was referenced Feb 9, 2026
…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.
This was referenced Feb 10, 2026
- 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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
…ding support