Skip to content

Migrate ToolTask and Al task to TaskEnvironment API#13423

Merged
OvesN merged 20 commits intodotnet:mainfrom
OvesN:dev/veronikao/migrate-Al-task-to-TaskEnvironment-API
Apr 7, 2026
Merged

Migrate ToolTask and Al task to TaskEnvironment API#13423
OvesN merged 20 commits intodotnet:mainfrom
OvesN:dev/veronikao/migrate-Al-task-to-TaskEnvironment-API

Conversation

@OvesN
Copy link
Copy Markdown
Contributor

@OvesN OvesN commented Mar 20, 2026

Fixes #13410
Fixes #13447

Context

The ToolTask and AL (Assembly Linker) task were migrated to use TaskEnvironment.

Changes Made

ToolTask.cs

  • Implemented IMultiThreadableTask — all ToolTask children now inherit TaskEnvironment with a default MultiProcessTaskEnvironmentDriver.
  • GetProcessStartInfo — uses TaskEnvironment.GetProcessStartInfo() to create the ProcessStartInfo in both
    multi-process and multithreaded modes. Applies GetWorkingDirectory() override (absolutized via
    TaskEnvironment.GetAbsolutePath()) and task-level EnvironmentVariables/EnvironmentOverride on top.
  • Environment.GetEnvironmentVariable was replaced with the TaskEnvironment API call.
  • Routed file existence checks and path resolution through TaskEnvironment.GetAbsolutePath().

Al.cs

  • Environment.GetEnvironmentVariable was replaced with the TaskEnvironment API call.
  • Routed file existence checks and path resolution through TaskEnvironment.GetAbsolutePath().

Testing

New unit tests in Al_Tests.cs and ToolTask_Tests.cs

Copilot AI review requested due to automatic review settings March 20, 2026 13:25
@OvesN OvesN requested review from AR-May and JanProvaznik March 20, 2026 13:26
Copy link
Copy Markdown
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 the AL built-in task to the TaskEnvironment API to support thread-safe execution in multithreaded builds, and introduces a reusable ToolTask helper for propagating TaskEnvironment working directory/environment to spawned tool processes.

Changes:

  • Updated AL to implement IMultiThreadableTask, use TaskEnvironment for env var/path resolution, and override process start info creation to flow the virtualized environment/working directory.
  • Refactored ToolTask process start info creation and added GetProcessStartInfoMultiThreaded helper to apply TaskEnvironment settings to child processes.
  • Added/updated unit tests validating AL and ToolTask propagation behavior.

Reviewed changes

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

File Description
src/Utilities/ToolTask.cs Extracts base PSI creation and adds a multithreaded helper to apply TaskEnvironment env/working directory.
src/Utilities.UnitTests/ToolTask_Tests.cs Adds coverage for GetProcessStartInfoMultiThreaded propagation and override precedence.
src/Tasks/Al.cs Makes AL multithreadable and routes env/path/process creation through TaskEnvironment.
src/Tasks.UnitTests/Al_Tests.cs Updates existing tests to set TaskEnvironment and adds new tests for tool path + working directory propagation.

Comment thread src/Utilities/ToolTask.cs Outdated
Comment thread src/Utilities/ToolTask.cs Outdated
Comment thread src/Utilities.UnitTests/ToolTask_Tests.cs
Comment thread src/Utilities.UnitTests/ToolTask_Tests.cs Outdated
Comment thread src/Utilities/ToolTask.cs Outdated
Comment thread src/Utilities/ToolTask.cs Outdated
Comment thread src/Utilities/ToolTask.cs Outdated
Comment thread src/Tasks/Al.cs
Comment thread src/Tasks/Al.cs
Comment thread src/Tasks/Al.cs
Comment thread src/Tasks/Al.cs Outdated
Copy link
Copy Markdown
Member

@AR-May AR-May left a comment

Choose a reason for hiding this comment

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

Looks good to me, provided that @rainersigwald approves the change of public API in ToolTask. Just one small refactoring idea from me.

Comment thread src/Utilities/ToolTask.cs Outdated
Copy link
Copy Markdown
Member

@JanProvaznik JanProvaznik left a comment

Choose a reason for hiding this comment

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

extra file slipped in, I deleted it
lgtm let's wait for confirming with Rainer this change to ToolTask is acceptable

Copy link
Copy Markdown
Member

@AR-May AR-May left a comment

Choose a reason for hiding this comment

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

Looks like there is a bug in mt route, @OvesN can you please take a look?

Comment thread src/Utilities/ToolTask.cs Outdated
Comment thread src/Utilities/ToolTask.cs Outdated
Comment thread src/Utilities/ToolTask.cs
@OvesN OvesN changed the title Migrate Al task to TaskEnvironment API Migrate ToolTask and Al task to TaskEnvironment API Mar 26, 2026
@OvesN OvesN marked this pull request as draft March 26, 2026 15:52
OvesN and others added 3 commits March 26, 2026 16:54
The test relied on FileAttributes.ReadOnly to force File.Delete to throw,
but this is not cross-platform - Unix read-only attributes don't prevent deletion.
@OvesN OvesN marked this pull request as ready for review March 27, 2026 16:22
@OvesN OvesN requested a review from rainersigwald March 27, 2026 17:28
rainersigwald
rainersigwald previously approved these changes Mar 27, 2026
Comment thread src/Utilities/ToolTask.cs
Comment thread src/Utilities/ToolTask.cs Outdated
Comment thread src/Utilities/ToolTask.cs Outdated
Comment thread src/Tasks.UnitTests/Al_Tests.cs Outdated
@rainersigwald rainersigwald dismissed their stale review March 27, 2026 18:08

I meant to "comment" not approve, sorry.

Comment thread src/Utilities/ToolTask.cs Outdated
Comment thread src/Utilities/ToolTask.cs Outdated
Comment thread src/Framework/TaskEnvironment.cs Outdated
OvesN and others added 3 commits March 30, 2026 14:38
ApplyEnvironmentOverrides  moved inside SetUpProcessStartInfo.
Added override for DeleteTempFile using AbsolutePath.
Made Driver private again, expose only enum value to decided if driver is multitheaded.
Made GetProcessStartInfoMultithreadable private.
add overload for DeleteTempFile with AbsolutePath argument
Comment thread src/Utilities/ToolTask.cs Outdated
Comment thread src/Utilities/ToolTask.cs Outdated
Copy link
Copy Markdown
Member

@AR-May AR-May left a comment

Choose a reason for hiding this comment

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

Looks good to me.

Comment thread src/Utilities.UnitTests/ToolTask_Tests.cs Outdated
Comment thread src/Utilities.UnitTests/ToolTask_Tests.cs Outdated
Comment thread src/Utilities/ToolTask.cs
@OvesN OvesN merged commit 932ab6a into dotnet:main Apr 7, 2026
10 checks passed
dfederm pushed a commit to dfederm/msbuild that referenced this pull request Apr 9, 2026
OvesN added a commit that referenced this pull request Apr 15, 2026
Fixes #13455
### Context

The SGen task was made thread-safe.

### Changes Made

**SGen.cs**

- Routed file existence checks and path resolution through
TaskEnvironment.GetAbsolutePath().

### Testing

Unit tests in `SGen_Tests.cs`

### Notes

- Should be merged after [Migrate ToolTask and Al task to
TaskEnvironment API
#13423](#13423)

---------

Co-authored-by: Jan Provazník <janprovaznik@microsoft.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.

Migrate ToolTask task to TaskEnvironment API Migrate Al task to TaskEnvironment API

5 participants