Skip to content

Migrate GetInstalledSDKLocations to Task Environment API#13564

Open
OvesN wants to merge 5 commits intodotnet:mainfrom
OvesN:dev/veronika/migrate-GetInstalledSDKLocations-to-Task-Environment-API
Open

Migrate GetInstalledSDKLocations to Task Environment API#13564
OvesN wants to merge 5 commits intodotnet:mainfrom
OvesN:dev/veronika/migrate-GetInstalledSDKLocations-to-Task-Environment-API

Conversation

@OvesN
Copy link
Copy Markdown
Contributor

@OvesN OvesN commented Apr 17, 2026

Fixes #13562

Context

The GetInstalledSDKLocationstask was made thread-safe.

Changes Made

Routed path resolution through TaskEnvironment.GetAbsolutePath().

Testing

Unit tests in GetInstalledSDKLocations_Tests.cs

…ullPath

The optimization in GetCanonicalForm() that skipped Path.GetFullPath for paths
without relative segments, separator issues, or consecutive separators caused
invalid path characters to be silently accepted. This broke tasks that relied
on Path.GetFullPath throwing for invalid characters.

Simplify GetCanonicalForm() to always call Path.GetFullPath, ensuring consistent
behavior with the BCL including rejection of invalid path characters.

Add test verifying GetCanonicalForm() throws the same exception as Path.GetFullPath
for paths containing invalid characters (null character).

Fixes dotnet#13514

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@OvesN OvesN self-assigned this Apr 17, 2026
@OvesN OvesN force-pushed the dev/veronika/migrate-GetInstalledSDKLocations-to-Task-Environment-API branch from 94cefdc to 7a73dc7 Compare April 17, 2026 18:01
@OvesN
Copy link
Copy Markdown
Contributor Author

OvesN commented Apr 17, 2026

/review

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 17, 2026

Expert Code Review (command) completed successfully!

Concurrency & Thread Safety — LGTM

Analysis: The new code (AbsolutizePaths, TaskEnvironment property, and their integration into Execute()) operates exclusively on per-instance state. MSBuild creates a separate task instance per invocation, and the engine sets TaskEnvironment on the instance before calling Execute() in a single-threaded setup phase (TaskExecutionHost.InitializeTaskClass). AbsolutizePaths allocates a fresh local array, reads only instance fields (paths param, TaskEnvironment), and delegates to TaskEnvironment.GetAbsolutePath() which is backed by a stateless singleton driver (MultiProcessTaskEnvironmentDriver.Instance) or a per-task isolated driver. No shared mutable state is touched by the new code paths.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Note

🔒 Integrity filter blocked 1 item

The following item were blocked because they don't meet the GitHub integrity level.

  • #13564 pull_request_read: has lower integrity than agent requires. The agent cannot read data with integrity below "approved".

To allow these resources, lower min-integrity in your GitHub frontmatter:

tools:
  github:
    min-integrity: approved  # merged | approved | unapproved | none

Generated by Expert Code Review (command) for issue #13564 · ● 17.2M

Comment thread src/Tasks.UnitTests/GetInstalledSDKLocations_Tests.cs Outdated
Comment thread src/Tasks.UnitTests/GetInstalledSDKLocations_Tests.cs Outdated
@OvesN OvesN requested review from AR-May and JanProvaznik April 20, 2026 13:16
@OvesN OvesN marked this pull request as ready for review April 20, 2026 13:16
Copilot AI review requested due to automatic review settings April 20, 2026 13:16
Comment thread src/Tasks/GetInstalledSDKLocations.cs Outdated
Copy link
Copy Markdown
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 migrates GetInstalledSDKLocations toward MSBuild’s multithreaded task execution model by implementing the Task Environment API for path resolution, with accompanying unit coverage.

Changes:

  • Marked GetInstalledSDKLocations as an [MSBuildMultiThreadableTask] and implemented IMultiThreadableTask.
  • Routed SDK root path resolution through TaskEnvironment.GetAbsolutePath() before calling ToolLocationHelper.
  • Added a new unit test validating relative-root resolution behavior via TaskEnvironment.

Reviewed changes

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

File Description
src/Tasks/GetInstalledSDKLocations.cs Declares the task as multi-threadable and resolves SDK root paths via TaskEnvironment.
src/Tasks.UnitTests/GetInstalledSDKLocations_Tests.cs Adds a new test fixture targeting TaskEnvironment-based path absolutization behavior.

Comment thread src/Tasks/GetInstalledSDKLocations.cs Outdated
Comment thread src/Tasks.UnitTests/GetInstalledSDKLocations_Tests.cs
Comment thread src/Tasks.UnitTests/GetInstalledSDKLocations_Tests.cs
Comment thread src/Tasks.UnitTests/GetInstalledSDKLocations_Tests.cs Outdated
Comment thread src/Tasks/GetInstalledSDKLocations.cs
Comment thread src/Tasks/TaskEnvironmentExtensions.cs
Copy link
Copy Markdown
Member

@AR-May AR-May left a comment

Choose a reason for hiding this comment

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

I have a couple of minor comments, otherwise lgtm!

/// Returns <see langword="null"/> if <paramref name="paths"/> is <see langword="null"/>.
/// Empty or null entries are passed through unchanged.
/// </summary>
internal static string[]? GetAbsolutePathsOrNull(this TaskEnvironment taskEnvironment, string[]? paths)
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.

we should prefer to work with AbsolutePaths once we converted to them and avoid conversions back to string if possible. Can we re-write this helper function (which would be super helpful) to return AbsolutePaths?


// TaskEnvironment pointing at the WRONG parent — same relative name resolves
// to a non-existent directory, proving resolution goes through TaskEnvironment.
string wrongParent = _env.CreateFolder().Path;
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.

I am a bit confused, it looks like start of another test here. Should not we separate them?

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.

Migrate GetInstalledSDKLocations to Task Environment API

4 participants