Skip to content

Move task environment drivers to Framework.#13380

Merged
SimaTian merged 3 commits intodotnet:mainfrom
AR-May:move-task-env-drivers
Mar 17, 2026
Merged

Move task environment drivers to Framework.#13380
SimaTian merged 3 commits intodotnet:mainfrom
AR-May:move-task-env-drivers

Conversation

@AR-May
Copy link
Member

@AR-May AR-May commented Mar 13, 2026

Context

Task environment drivers must be moved to Framework projects so they can be invoked from tasks. This is a prerequisite for the RAR task enlightening and for fixing #13374.

Changes Made

  • Moved the task environment drivers to the Framework project
  • Moved environment-related function from CommunicationsUtilities to the Framework project
  • Split in half DebugUtils and moved relevant part to the Framework project. There is quite weird code path in CommunicationsUtilities.GetEnvironmentVariablesWindows where it ensures the DebugUtils static constructor is called because it sets the environment variables that we would like then to propagate to other msbuild processes.

Testing

  • Unit tests
  • Exp insertion

Copilot AI review requested due to automatic review settings March 13, 2026 11:17
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 refactors MSBuild’s debugging and environment-variable handling by moving the relevant helper logic out of Shared/Internal and into Microsoft.Build.Framework-scoped helpers, then updating engine/taskhost/unit-test call sites accordingly.

Changes:

  • Introduces FrameworkDebugUtils and FrameworkCommunicationsUtilities in src/Framework and updates call sites to use them.
  • Removes the environment-variable caching/restore helpers from src/Shared/CommunicationsUtilities.cs and rehomes that logic in the Framework layer.
  • Moves task environment drivers to the Microsoft.Build.Framework namespace and updates the engine/tests to use the relocated types.

Reviewed changes

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

Show a summary per file
File Description
src/Shared/UnitTests/CommunicationUtilities_Tests.cs Updates env-var tests to use FrameworkCommunicationsUtilities.
src/Shared/Debugging/PrintLineDebugger.cs Switches process-info prefix source to FrameworkDebugUtils.
src/Shared/Debugging/DebugUtils.cs Removes static init responsibilities and delegates debug-path usage to FrameworkDebugUtils.
src/Shared/CommunicationsUtilities.cs Removes env-var caching/restore logic and updates trace dump path to use FrameworkDebugUtils.
src/MSBuild/XMake.cs Uses FrameworkDebugUtils for debug-path and TaskHost-node detection.
src/MSBuild/OutOfProcTaskHostNode.cs Switches env snapshot/restore to FrameworkCommunicationsUtilities.
src/Framework/MultiThreadedTaskEnvironmentDriver.cs Moves driver into Microsoft.Build.Framework and uses framework env-var comparer.
src/Framework/MultiProcessTaskEnvironmentDriver.cs Moves driver into Microsoft.Build.Framework and uses FrameworkCommunicationsUtilities/NativeMethods.
src/Framework/DebugUtils.cs Adds FrameworkDebugUtils (debug path + process diagnostics).
src/Framework/CommunicationsUtilities.cs Adds FrameworkCommunicationsUtilities (env-var caching + set/restore).
src/Build/Utilities/Utilities.cs Switches environment properties sourcing to FrameworkCommunicationsUtilities.
src/Build/Microsoft.Build.csproj Stops compiling task environment drivers from the Build project (now in Framework).
src/Build/BackEnd/Node/OutOfProcServerNode.cs Uses FrameworkCommunicationsUtilities.SetEnvironment.
src/Build/BackEnd/Node/OutOfProcNode.cs Uses FrameworkCommunicationsUtilities for env snapshot/restore.
src/Build/BackEnd/Node/InProcNode.cs Uses FrameworkCommunicationsUtilities for env snapshot/restore.
src/Build/BackEnd/Components/Scheduler/Scheduler.cs Uses FrameworkDebugUtils.DebugPath.
src/Build/BackEnd/Components/BuildRequestEngine/BuildRequestEngine.cs Uses FrameworkDebugUtils.DebugPath.
src/Build/BackEnd/BuildManager/BuildParameters.cs Uses FrameworkCommunicationsUtilities for env snapshots.
src/Build/BackEnd/BuildManager/BuildManager.cs Uses FrameworkDebugUtils for debug gating and process info strings.
src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs Updates tests to call FrameworkDebugUtils.SetDebugPath.
src/Build.UnitTests/BackEnd/DebugUtils_tests.cs Updates tests to validate FrameworkDebugUtils behavior.

@AR-May AR-May mentioned this pull request Mar 13, 2026
6 tasks
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@SimaTian SimaTian merged commit f2213b0 into dotnet:main Mar 17, 2026
10 checks passed
AR-May added a commit to AR-May/msbuild that referenced this pull request Mar 19, 2026
### Context
Task environment drivers must be moved to Framework projects so they can
be invoked from tasks. This is a prerequisite for the RAR task
enlightening and for fixing dotnet#13374.

### Changes Made
- Moved the task environment drivers to the Framework project
- Moved environment-related function from `CommunicationsUtilities` to
the Framework project
- Split in half `DebugUtils` and moved relevant part to the Framework
project. There is quite weird code path in
`CommunicationsUtilities.GetEnvironmentVariablesWindows` where it
ensures the DebugUtils static constructor is called because it sets the
environment variables that we would like then to propagate to other
msbuild processes.

### Testing
- [x] Unit tests
- [ ] Exp insertion

---------

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Jan Provazník <janprovaznik@microsoft.com>
@AR-May AR-May self-assigned this Mar 20, 2026
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.

5 participants