-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Implement task environment APIs #12651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 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 |
| /// <inheritdoc/> | ||
| public AbsolutePath GetAbsolutePath(string path) | ||
| { | ||
| return new AbsolutePath(path, ProjectDirectory); |
Copilot
AI
Oct 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation incorrectly assumes the input path is always relative. If an absolute path is passed, it will be incorrectly combined with ProjectDirectory. Should check if the path is already absolute first.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If input path is absolute, then combining it with other absolute path would have no effect - it will stay intact, so there is no bug.
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, needs another reviewer
| /// for use in multithreaded mode where tasks may be executed in parallel. This allows each project to maintain its own | ||
| /// isolated environment state without affecting other concurrently building projects. | ||
| /// </summary> | ||
| internal sealed class MultithreadedTaskEnvironmentDriver : ITaskEnvironmentDriver |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| internal sealed class MultithreadedTaskEnvironmentDriver : ITaskEnvironmentDriver | |
| internal sealed class MultiThreadedTaskEnvironmentDriver : ITaskEnvironmentDriver |
consistency
| /// String comparer for environment variable names based on the current platform. | ||
| /// On Windows, environment variables are case-insensitive; on Unix-like systems, they are case-sensitive. | ||
| /// </summary> | ||
| private static readonly StringComparer EnvironmentVariableComparer = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
consider if this should not be in EnvironmentUtilities
|
|
||
| namespace Microsoft.Build.UnitTests | ||
| { | ||
| public class TaskEnvironmentTests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| public class TaskEnvironmentTests | |
| public class TaskEnvironment_Tests |
consistency
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| #nullable enable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this the default?
Fixes #11828
Context
Implement the new task environment APIs
Testing
Added unit tests