Skip to content

Add GetCanonicalForm to the AbsolutePath API#13088

Merged
AR-May merged 9 commits into
dotnet:mainfrom
AR-May:update-absolute-path-api
Feb 9, 2026
Merged

Add GetCanonicalForm to the AbsolutePath API#13088
AR-May merged 9 commits into
dotnet:mainfrom
AR-May:update-absolute-path-api

Conversation

@AR-May

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

Copy link
Copy Markdown
Member

Context

It is quite often that Path.GetFullPath is used in the tasks code. For enlightening we would want to replace it with our own API. The candidate was TaskEnvironment.GetAbsolutePath for replacing.

However, they do not do the same set of actions. TaskEnvironment.GetAbsolutePath only absolutizes the path but does not resolve possible "." and ".." in the path or normalize path separators on Windows.
For some scenarios this is critical, for some that does not matter. We should provide an option for fully copy Path.GetFullPath behavior

Changes Made

  • Added AbsolutePath.GetCanonicalForm()

Testing

Added unit tests

@AR-May AR-May marked this pull request as ready for review January 22, 2026 13:52
Copilot AI review requested due to automatic review settings January 22, 2026 13:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 adds a GetFullPath() method to the AbsolutePath struct to provide an API that fully replicates Path.GetFullPath behavior, including resolving relative path segments ("." and "..") and normalizing directory separators on Windows. This enables replacing direct Path.GetFullPath calls in task code with a more controlled API.

Changes:

  • Added GetFullPath() method with optimization to avoid allocations when no normalization is needed
  • Added comprehensive unit tests for both Windows and Unix platforms

Reviewed changes

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

File Description
src/Framework/PathHelpers/AbsolutePath.cs Implements GetFullPath() with detection logic for relative segments and separator normalization needs
src/Framework.UnitTests/AbsolutePath_Tests.cs Adds test cases for null paths, Windows path normalization, and Unix path normalization

Comment thread src/Framework.UnitTests/AbsolutePath_Tests.cs
Comment thread src/Framework/PathHelpers/AbsolutePath.cs Outdated
Comment thread src/Framework/PathHelpers/AbsolutePath.cs
Comment thread src/Framework/PathHelpers/AbsolutePath.cs Outdated
@AR-May AR-May force-pushed the update-absolute-path-api branch from f1d94ca to d9b4d89 Compare January 28, 2026 12:26

@JanProvaznik JanProvaznik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should this pr also use this new method on the already migrated tasks where needed?

Comment thread src/Framework/PathHelpers/AbsolutePath.cs Outdated
Comment thread src/Framework/PathHelpers/AbsolutePath.cs Outdated
Comment thread src/Framework/PathHelpers/AbsolutePath.cs
@AR-May AR-May changed the title Add GetFullPath to the AbsolutePath API Add GetCanonicalForm to the AbsolutePath API Jan 28, 2026
@AR-May AR-May self-assigned this Jan 28, 2026
@AR-May

AR-May commented Jan 28, 2026

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@AR-May

AR-May commented Jan 29, 2026

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@AR-May

AR-May commented Jan 30, 2026

Copy link
Copy Markdown
Member Author

should this pr also use this new method on the already migrated tasks where needed?

let me do it in separate pr for that, i would like to get this in and start using in my draft prs.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

Comment thread src/Framework/PathHelpers/AbsolutePath.cs
Comment thread src/Framework/PathHelpers/AbsolutePath.cs
Comment thread src/Framework.UnitTests/AbsolutePath_Tests.cs
Comment thread src/Framework/PathHelpers/AbsolutePath.cs
Comment thread src/Framework/PathHelpers/AbsolutePath.cs
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.

3 participants