Expose public API for TaskEnvironment construction#13383
Merged
AR-May merged 9 commits intodotnet:mainfrom Mar 30, 2026
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to make Microsoft.Build.Framework.TaskEnvironment directly instantiable by task authors by adding a public parameterless constructor that selects a default environment driver.
Changes:
- Add a public
TaskEnvironment()constructor intended to default to the multi-process driver.
Member
Author
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Member
Can you elaborate on the use case for this? |
Member
rainersigwald
left a comment
There was a problem hiding this comment.
Should we adjust our internal uses to this?
- public TaskEnvironment TaskEnvironment { get; set; } = new TaskEnvironment(MultiProcessTaskEnvironmentDriver.Instance);
+ public TaskEnvironment TaskEnvironment { get; set; } = TaskEnvironment.Default;?
Member
Author
Yes, for sure, was going to make it in a separate PR as did not want to mix public API change with refactoring. |
Member
Author
The same use as we planning to add soon in msbuild repo - in tests. Allowing customers test the isolation of the task like we plan in #13373. |
AR-May
commented
Mar 25, 2026
AR-May
commented
Mar 25, 2026
rainersigwald
approved these changes
Mar 27, 2026
baronfel
approved these changes
Mar 27, 2026
This was referenced Mar 30, 2026
dfederm
pushed a commit
to dfederm/msbuild
that referenced
this pull request
Apr 9, 2026
### Context With the discovery of the "direct instantiation of the task" use case, tasks must explicitly set a default task environment in order to work correctly. Task authors may encounter the same issue, without having benefit of having framework internals visible to them and thus without ability to create one without re-implementing the driver themselves. So, we need to provide a public API for `TaskEnvironment` construction to enable setting the default task environment. Would be helpful for sdk as well. ### Changes Made Adds two public API members to `TaskEnvironment` so that task authors using `IMultiThreadableTask` can obtain or create a `TaskEnvironment` without depending on internal types: - `TaskEnvironment.Default`: static singleton that delegates to the process-level environment (multi-process mode). - `TaskEnvironment.CreateMultiThreaded(projectDirectory, environmentVariables?)`: factory method that creates an isolated environment for multithreaded execution mode. ### Testing Unit tests ### Note Depends on dotnet#13380
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
With the discovery of the "direct instantiation of the task" use case, tasks must explicitly set a default task environment in order to work correctly. Task authors may encounter the same issue, without having benefit of having framework internals visible to them and thus without ability to create one without re-implementing the driver themselves. So, we need to provide a public API for
TaskEnvironmentconstruction to enable setting the default task environment. Would be helpful for sdk as well.Changes Made
Adds two public API members to
TaskEnvironmentso that task authors usingIMultiThreadableTaskcan obtain or create aTaskEnvironmentwithout depending on internal types:TaskEnvironment.Default: static singleton that delegates to the process-level environment (multi-process mode).TaskEnvironment.CreateMultiThreaded(projectDirectory, environmentVariables?): factory method that creates an isolated environment for multithreaded execution mode.Testing
Unit tests
Note
Depends on #13380