Skip to content

Make task environment path absolutization not throw.#13035

Merged
AR-May merged 5 commits intodotnet:mainfrom
AR-May:fix-task-environment-absolutization
Jan 16, 2026
Merged

Make task environment path absolutization not throw.#13035
AR-May merged 5 commits intodotnet:mainfrom
AR-May:fix-task-environment-absolutization

Conversation

@AR-May
Copy link
Member

@AR-May AR-May commented Jan 15, 2026

Context

TaskEnvironment.GetAbsolutePath can throw exceptions during multi‑process execution. This issue can be mostly avoided by using Microsoft.IO.Path.Combine in .NET Framework MSBuild and System.IO.Path.Combine in .NET Core MSBuild in the underlying implementations. This way the only exception could be thrown on null argument.

Changes Made

Start using Path.Combine for all AsbolutePath creations.

Testing

Added a unit test for this case.

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 fixes an issue where TaskEnvironment.GetAbsolutePath throws exceptions during multi-process execution when encountering paths with invalid characters. The fix changes from using Path.GetFullPath to using Path.Combine in the MultiProcessTaskEnvironmentDriver.GetAbsolutePath method.

Changes:

  • Replaced Path.GetFullPath with Path.Combine in MultiProcessTaskEnvironmentDriver.GetAbsolutePath to avoid exceptions on invalid path characters
  • Added conditional compilation directives to use Microsoft.IO.Path for .NET Framework and System.IO.Path for .NET Core
  • Added a unit test to verify the fix handles invalid path characters without throwing
  • Minor documentation improvements (XML comment references and clarifications)

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
src/Framework/TaskEnvironment.cs Updated XML comment to use proper <see cref> syntax for ProjectDirectory; removed trailing whitespace
src/Build/BackEnd/TaskExecutionHost/MultiThreadedTaskEnvironmentDriver.cs Improved comment clarity by specifying "functions used in project files"
src/Build/BackEnd/TaskExecutionHost/MultiProcessTaskEnvironmentDriver.cs Added conditional imports for Microsoft.IO vs System.IO; replaced Path.GetFullPath with Path.Combine in GetAbsolutePath implementation
src/Build.UnitTests/BackEnd/TaskEnvironment_Tests.cs Added test case to verify GetAbsolutePath doesn't throw with invalid path characters

@AR-May
Copy link
Member Author

AR-May commented Jan 16, 2026

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@AR-May
Copy link
Member Author

AR-May commented Jan 16, 2026

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

This was referenced Mar 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants