Implement task environment APIs#12651
Merged
JanProvaznik merged 25 commits intodotnet:mainfrom Nov 27, 2025
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR implements task environment APIs to provide abstracted access to environment variables and working directory for MSBuild tasks. The implementation supports both single-threaded (stub) and multithreaded execution modes through a driver pattern.
Key changes:
- Replaced
NotImplementedExceptionstubs with functional implementations using a driver pattern - Added driver interface and two concrete implementations for different execution modes
- Implemented path validation and conversion utilities for the
AbsolutePathtype
Reviewed Changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
src/Framework/TaskEnvironment.cs |
Updated to use driver pattern instead of throwing NotImplementedException |
src/Framework/ITaskEnvironmentDriver.cs |
Added interface defining environment operations contract |
src/Framework/StubTaskEnvironmentDriver.cs |
Implemented driver that directly modifies system environment |
src/Framework/MultithreadedTaskEnvironmentDriver.cs |
Implemented driver with isolated environment for concurrent execution |
src/Framework/PathHelpers/AbsolutePath.cs |
Added path validation and conversion functionality |
src/Framework.UnitTests/TaskEnvironment_Tests.cs |
Added comprehensive unit tests for task environment functionality |
src/Framework.UnitTests/AbsolutePath_Tests.cs |
Added unit tests for AbsolutePath implementation |
src/Build/BackEnd/TaskExecutionHost/MultiThreadedTaskEnvironmentDriver.cs
Show resolved
Hide resolved
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Member
JanProvaznik
left a comment
There was a problem hiding this comment.
OK, needs another reviewer
src/Build/BackEnd/TaskExecutionHost/MultiThreadedTaskEnvironmentDriver.cs
Show resolved
Hide resolved
src/Build/BackEnd/TaskExecutionHost/MultiThreadedTaskEnvironmentDriver.cs
Show resolved
Hide resolved
src/Build/BackEnd/TaskExecutionHost/MultiProcessTaskEnvironmentDriver.cs
Show resolved
Hide resolved
Member
YuliiaKovalova
left a comment
There was a problem hiding this comment.
I understand that we operate on the different environment collections, but we apply the same manipulations.
Please make it universal and reusable to avoid duplications.
src/Build/BackEnd/TaskExecutionHost/MultiProcessTaskEnvironmentDriver.cs
Show resolved
Hide resolved
src/Build/BackEnd/TaskExecutionHost/MultiProcessTaskEnvironmentDriver.cs
Show resolved
Hide resolved
src/Build/BackEnd/TaskExecutionHost/MultiProcessTaskEnvironmentDriver.cs
Show resolved
Hide resolved
- Add EnvironmentVariableComparer to EnvironmentUtilities for platform-appropriate string comparison - Add CopyCurrentEnvironmentVariables() to EnvironmentUtilities for simple env var copying - Add SetEnvironment() to EnvironmentUtilities with delegate-based abstraction - Update MultiProcessTaskEnvironmentDriver and MultithreadedTaskEnvironmentDriver to use shared utilities - Update CommunicationsUtilities.SetEnvironment to delegate to EnvironmentUtilities (non-CLR2COMPATIBILITY) - Keep optimized GetEnvironmentVariables with caching/FrozenDictionary in CommunicationsUtilities
- Add GetEnvironmentVariables() to EnvironmentUtilities with caching and FrozenDictionary - Use P/Invoke on Windows for optimized environment variable reading - Update MultiProcessTaskEnvironmentDriver to use the cached method - Skip StringTools dependency (not available in Framework) - Exclude net35 (CLR2COMPATIBILITY) which doesn't have FrozenDictionary
YuliiaKovalova
approved these changes
Nov 27, 2025
This was referenced Nov 28, 2025
JanProvaznik
added a commit
that referenced
this pull request
Dec 3, 2025
rework of #12608 after merging #12651 fixes #11829, #11830 #12850 #12802 ### Context ### Changes Made 1. refactor communicationutilities to support the taskenvironmentdrivers 2. propagate taskenvironment throughout execution 3. enlightening intrinsic tasks ### Testing simple sample projects using the intrinsictasks build ### Notes "normal tasks" will be enlightened in subsequent PRs included the intrinsic tasks in this PR so it's integration testable --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.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.
Fixes #11828
Context
Implement the new task environment APIs
Testing
Added unit tests