Skip to content

Conversation

@AR-May
Copy link
Member

@AR-May AR-May commented Oct 15, 2025

Fixes #11828

Context

Implement the new task environment APIs

Testing

Added unit tests

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 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 NotImplementedException stubs 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 AbsolutePath type

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);
Copy link

Copilot AI Oct 15, 2025

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.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

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.

@AR-May AR-May marked this pull request as draft October 16, 2025 08:11
Copy link
Member

@JanProvaznik JanProvaznik left a 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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 =
Copy link
Member

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

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?

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.

Design and add new Task API Contract

2 participants