Move task environment drivers to Framework.#13380
Merged
SimaTian merged 3 commits intodotnet:mainfrom Mar 17, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
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
FrameworkDebugUtilsandFrameworkCommunicationsUtilitiesinsrc/Frameworkand updates call sites to use them. - Removes the environment-variable caching/restore helpers from
src/Shared/CommunicationsUtilities.csand rehomes that logic in the Framework layer. - Moves task environment drivers to the
Microsoft.Build.Frameworknamespace 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. |
JanProvaznik
approved these changes
Mar 13, 2026
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Mar 17, 2026
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>
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.
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
CommunicationsUtilitiesto the Framework projectDebugUtilsand moved relevant part to the Framework project. There is quite weird code path inCommunicationsUtilities.GetEnvironmentVariablesWindowswhere 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