Skip to content

Migrate Arcade.Sdk and Helix tasks to the multithreaded task model - #17525

Merged
ViktorHofer merged 11 commits into
dotnet:mainfrom
ViktorHofer:mt-safe-subset-6
Sep 10, 2026
Merged

ViktorHofer merged 11 commits into
dotnet:mainfrom
ViktorHofer:mt-safe-subset-6

Conversation

@ViktorHofer

@ViktorHofer ViktorHofer commented Sep 9, 2026 •

Copy link
Copy Markdown
Member

Sixth safe subset of #17381: Microsoft.DotNet.Arcade.Sdk and Microsoft.DotNet.Helix. Two independent assemblies, both with in-repo test suites.

18 tasks annotated with [MSBuildMultiThreadableTask]; paths and environment reads go through TaskEnvironment.

  • XHarnessTaskBase implements IMultiThreadableTask so the shared base members come under analyzer coverage, while the attribute stays on the two concrete tasks — routing keys off the attribute alone.
  • SingleError deliberately stays out: GetRegisteredTaskObject/RegisterTaskObject is not atomic, so concurrent instances with the same Text could both log, defeating the single-error contract.
  • SendHelixJob and InstallDotNetTool implement the interface without the attribute, so they keep routing through the TaskHost. InstallDotNetTool launches a child process through ICommandFactory, which builds its ProcessStartInfo from the ambient environment rather than the project's. SendHelixJob reaches the JobSender/HelixApi stack, which has not been audited for shared mutable state and is the most side-effecting task in the SDK; tracked for a follow-up change.
  • LocateDotNet canonicalizes the resolved path with GetCanonicalForm() so the DotNetPath output keeps the shape the previous Path.GetFullPath produced — GetAbsolutePath anchors, it does not normalize. It also skips malformed PATH entries instead of throwing, since GetAbsolutePath validates where the previous File.Exists probe just returned false, and reports a clear error when PATH is unset.
  • InstallDotNetCore switches to TaskEnvironment.GetProcessStartInfo() so the child dotnet-install inherits the project's environment.
  • FindDotNetCliPackage._client is no longer static. It was reassigned on every execution, so sharing it across instances was a race rather than pooling.
  • Inputs that name a file are guarded before resolution: an empty value keeps its original diagnostic instead of throwing, and a bare executable name (DotNetTool becomes plain dotnet.exe when RepoLayout.props clears DotNetRoot) is left unresolved so it still resolves on PATH.

Validation

  • Full build is clean, and both test suites pass apart from one pre-existing CentralPackageManagementTests failure (SwixBuild NU1009) that this PR does not touch.
  • The two XHarness test updates account for the payload archive path becoming absolute; archive contents are unchanged, since entry names are filename- or base-relative.
  • Positive control: reverting one call site in each assembly produces MSBuildTask0003/MSBuildTask0002, confirming the analyzer is live and the clean run is meaningful.

Annotates 18 tasks across Microsoft.DotNet.Arcade.Sdk and Microsoft.DotNet.Helix
with [MSBuildMultiThreadableTask] and routes their path and environment access
through TaskEnvironment.

- XHarnessTaskBase carries IMultiThreadableTask so the shared base members fall
  under the analyzer, while the attribute stays on the two concrete tasks, since
  routing keys off the attribute alone.
- SingleError stays out: its GetRegisteredTaskObject/RegisterTaskObject pair is
  not atomic, so concurrent instances could both log, defeating its contract.
- SendHelixJob and InstallDotNetTool implement the interface without the
  attribute so they keep routing through the TaskHost; both reach process-wide
  state that path resolution alone cannot make safe.
- LocateDotNet keeps Path.GetFullPath on the resolved path so the DotNetPath
  output stays canonical, and skips malformed PATH entries rather than throwing.
- FindDotNetCliPackage._client is no longer static. It was reassigned on every
  execution, so sharing it across instances was a race, not pooling.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
Copilot AI lite review requested due to automatic review settings September 9, 2026 16:02

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.

Copilot review overview

🟡 Changes recommended

Several newly introduced TaskEnvironment.GetAbsolutePath(...) call sites can throw on empty/malformed user input where the previous behavior was a non-throwing existence check, risking hard build failures.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Lite
Findings: 4 Medium severity

New issues introduced by this change (4)
Severity Finding
Medium severity src/​Microsoft.DotNet.Arcade.Sdk/​src/​DownloadFile.cs — In the file:// copy path, TaskEnvironment.GetAbsolutePath(filePath) can throw for malformed…
Medium severity src/​Microsoft.DotNet.Helix/​Sdk/​CreateXHarnessAndroidWorkItems.cs — apkPath = TaskEnvironment.GetAbsolutePath(apkPath) can throw if the item spec/metadata is empty…
Medium severity src/​Microsoft.DotNet.Helix/​Sdk/​CreateXHarnessAppleWorkItems.cs — appFolderPath = TaskEnvironment.GetAbsolutePath(appFolderPath) can throw if the item…
Medium severity src/​Microsoft.DotNet.Helix/​Sdk/​SendHelixJob.cs — TaskEnvironment.GetAbsolutePath(path) will throw for empty or malformed item specs, whereas the…
What changed in this PR

Migrates a set of Microsoft.DotNet.Arcade.Sdk and Microsoft.DotNet.Helix MSBuild tasks toward MSBuild’s multithreaded task model by opting tasks into [MSBuildMultiThreadableTask], implementing IMultiThreadableTask, and routing path/environment resolution through TaskEnvironment to make per-project execution safer under -mt.

Changes:

  • Annotate additional tasks as multithreadable and/or implement IMultiThreadableTask to enable TaskEnvironment injection.
  • Replace direct path/environment usage with TaskEnvironment-based resolution, and adjust Helix XHarness behavior (including test expectations) for absolute payload paths.
  • Update process spawning and IO call sites to avoid binding to process-wide state in multithreaded/shared-node scenarios.
File Description
src/​Microsoft.DotNet.Helix/​Sdk/​XharnessTaskBase.cs Makes shared XHarness base participate in IMultiThreadableTask/TaskEnvironment injection.
src/​Microsoft.DotNet.Helix/​Sdk/​SendHelixJob.cs Uses TaskEnvironment for env/path resolution while intentionally keeping TaskHost routing.
src/​Microsoft.DotNet.Helix/​Sdk/​InstallDotNetTool.cs Injects TaskEnvironment for path resolution while intentionally keeping TaskHost routing.
src/​Microsoft.DotNet.Helix/​Sdk/​FindDotNetCliPackage.cs Marks task multithreadable and removes static client to avoid cross-instance races.
src/​Microsoft.DotNet.Helix/​Sdk/​DownloadFromResultsContainer.cs Opts into multithreading and resolves output paths via TaskEnvironment.
src/​Microsoft.DotNet.Helix/​Sdk/​CreateXHarnessAppleWorkItems.cs Opts into multithreading and resolves bundle/tmp paths via TaskEnvironment.
src/​Microsoft.DotNet.Helix/​Sdk/​CreateXHarnessAndroidWorkItems.cs Opts into multithreading and resolves APK paths via TaskEnvironment.
src/​Microsoft.DotNet.Helix/​Sdk/​BaseTask.cs Minor cleanup of base task type reference/import.
src/​Microsoft.DotNet.Helix/​Sdk.Tests/​Microsoft.DotNet.Helix.Sdk.Tests/​CreateXHarnessAppleWorkItemsTests.cs Updates tests for absolute-path payload behavior.
src/​Microsoft.DotNet.Helix/​Sdk.Tests/​Microsoft.DotNet.Helix.Sdk.Tests/​CreateXHarnessAndroidWorkItemsTests.cs Updates tests for absolute-path payload behavior.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​ValidateLicense.cs Opts into multithreading and resolves inputs via TaskEnvironment.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​Unsign.cs Opts into multithreading and resolves file path via TaskEnvironment.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​SingleError.cs Documents why task is not opted into multithreading; keeps behavior consistent.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​SetCorFlags.cs Opts into multithreading and resolves file path via TaskEnvironment.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​SaveItems.cs Opts into multithreading and resolves output path via TaskEnvironment.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​LocateDotNet.cs Opts into multithreading and moves PATH/global.json resolution through TaskEnvironment.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​InstallDotNetCore.cs Opts into multithreading and starts dotnet-install using TaskEnvironment start info.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​GetLicenseFilePath.cs Opts into multithreading and resolves search directory via TaskEnvironment.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​GetAssemblyFullName.cs Opts into multithreading and resolves assembly paths via TaskEnvironment.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​GenerateSourcePackageSourceLinkTargetsFile.cs Opts into multithreading and resolves output path via TaskEnvironment.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​GenerateResxSource.cs Opts into multithreading and resolves input/output paths via TaskEnvironment.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​GenerateChecksums.cs Opts into multithreading and resolves item/destination paths via TaskEnvironment.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​ExtractNgenMethodList.cs Opts into multithreading and resolves input/output paths via TaskEnvironment.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​DownloadFile.cs Opts into multithreading and resolves destination/source paths via TaskEnvironment.
src/​Microsoft.DotNet.Arcade.Sdk/​src/​CheckRequiredDotNetVersion.cs Opts into multithreading and resolves global.json path via TaskEnvironment.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

GetAbsolutePath rejects a null or empty path, whereas the File/Directory
existence probes it replaced simply returned false. Where the path is
user-supplied, keep reporting the existing "not found" error rather than
throwing.

- SendHelixJob: correlation payload paths come from GetMetadata, which yields
  an empty string for absent metadata.
- CreateXHarnessAndroidWorkItems / CreateXHarnessAppleWorkItems: payload paths
  come from item metadata, and the Apple task's TrimEnd can itself empty the
  string for a path that is only a separator.
- Adds a regression test pinning the Android empty-path behavior.

LocateDotNet drops the try/catch added for malformed PATH entries. The two
argument AbsolutePath constructor only rejects null and empty, and splitting
PATH with RemoveEmptyEntries already rules those out, so the catch was
unreachable and its stated rationale wrong.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
Copilot AI review requested due to automatic review settings September 9, 2026 19:37

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.

Copilot review overview

🔵 Needs a closer look

A few updated tasks now resolve paths via TaskEnvironment but still log raw (possibly relative) inputs or log the wrong executable, which can mislead diagnostics and should be corrected.

Review tier: Lite
Findings: None

Issues resolved since last review (4)
Severity Finding
Medium severity src/​Microsoft.DotNet.Helix/​Sdk/​SendHelixJob.cs — TaskEnvironment.GetAbsolutePath(path) will throw for empty or malformed item specs, whereas the… View resolved comment
Medium severity src/​Microsoft.DotNet.Helix/​Sdk/​CreateXHarnessAppleWorkItems.cs — appFolderPath = TaskEnvironment.GetAbsolutePath(appFolderPath) can throw if the item… View resolved comment
Medium severity src/​Microsoft.DotNet.Helix/​Sdk/​CreateXHarnessAndroidWorkItems.cs — apkPath = TaskEnvironment.GetAbsolutePath(apkPath) can throw if the item spec/metadata is empty… View resolved comment
Medium severity src/​Microsoft.DotNet.Arcade.Sdk/​src/​DownloadFile.cs — In the file:// copy path, TaskEnvironment.GetAbsolutePath(filePath) can throw for malformed… View resolved comment
Suppressed comments (3)

Previously missed (3) — in code that hasn't changed since the last review.

src/Microsoft.DotNet.Arcade.Sdk/src/GetLicenseFilePath.cs:50

  • The directory being searched is now resolved via TaskEnvironment.GetAbsolutePath(Directory), but the error messages still print the raw Directory value. If Directory is relative, this can be confusing; log the resolved directory so the message matches the actual search location.
    src/Microsoft.DotNet.Arcade.Sdk/src/ValidateLicense.cs:38
  • The task resolves input paths via TaskEnvironment.GetAbsolutePath(...), but the mismatch error logs the raw LicensePath/ExpectedLicensePath values. If those are relative, the error message won’t reflect the actual files compared; log the resolved paths for clarity.
    src/Microsoft.DotNet.Helix/Sdk/InstallDotNetTool.cs:181
  • The log line uses DotnetPath, but the command actually runs executable (either dotnet from PATH or an absolute path resolved via TaskEnvironment). When DotnetPath is empty or relative, this message can be misleading for diagnostics; log executable instead.

The repo sets csharp_new_line_before_open_brace = all, but DownloadFile.cs
carries some older K&R style. Bring the three lines this PR already modifies
into line with the repo style. No behavior change.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
Copilot AI review requested due to automatic review settings September 10, 2026 09:46

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.

Copilot review overview

🔵 Needs a closer look

DownloadFromResultsContainer can throw when asked to download a filename without directory separators, which can crash the task for valid inputs.

Review tier: Lite
Findings: None

Suppressed comments (4)

Previously missed (3) — in code that hasn't changed since the last review.

src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs:98

  • When VersionsPropsPath is null/empty, the error message becomes "Unable to find translation file " (blank path), which makes it hard to diagnose the real problem (missing property value). Consider an explicit message that VersionsPropsPath was not provided.
    src/Microsoft.DotNet.Helix/Sdk/InstallDotNetTool.cs:181
  • The log message uses DotnetPath, but the command actually executes executable (either "dotnet" or an absolute path). When DotnetPath is empty this currently logs an empty executable, and when it’s relative the log won’t match what is executed; logging executable makes troubleshooting reliable.
    src/Microsoft.DotNet.Helix/Sdk/XharnessTaskBase.cs:15
  • The XML summary says this base task is for Android packages, but it’s also the shared base for the Apple work item task. Updating the summary avoids misleading API documentation and search results.

src/Microsoft.DotNet.Helix/Sdk/DownloadFromResultsContainer.cs:85

  • Path.GetDirectoryName(file) returns null when file is just a filename (no directory separators). Path.Combine(destinationDir.FullName, null) will then throw, which can crash the task for valid DownloadFilesFromResults values like "results.xml". Guard the directory creation for the no-subdirectory case.
            DirectoryInfo destinationDir = Directory.CreateDirectory(TaskEnvironment.GetAbsolutePath(Path.Combine(directoryPath, workItemName)));
            foreach (string file in filesToDownload)
            {
                try
                {

Replaces the local MSBuildTask0002 suppression with the existing
AbsolutePathExtensions.GetCanonicalForm polyfill, which Templating, CMake.Sdk
and XliffTasks already use for exactly this case. The suppression now lives in
one place, tracked by dotnet#17506, instead of
being duplicated per call site.

Behavior is unchanged: the polyfill is Path.GetFullPath over an already fully
qualified path, which is what the previous code computed.

Co-authored-by: Copilot <[email protected]>
Copilot-Session: be19d794-fe4f-43fe-9e6e-f6e6b13ec6e7
Copilot AI review requested due to automatic review settings September 10, 2026 10:04

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.

Copilot review overview

🔵 Needs a closer look

The changes affect MSBuild task routing/execution semantics across core Arcade/Helix tasks under multi-threaded builds, so a final human review is needed despite only minor localized issues found.

Review tier: Lite
Findings: None

Suppressed comments (3)

Previously missed (3) — in code that hasn't changed since the last review.

src/Microsoft.DotNet.Arcade.Sdk/src/ValidateLicense.cs:41

  • This task now resolves inputs via TaskEnvironment, so the error message can point at different (resolved) files than the raw LicensePath/ExpectedLicensePath values. Logging the resolved paths makes mismatches easier to diagnose when inputs are relative.
        var expectedLines = File.ReadAllLines(TaskEnvironment.GetAbsolutePath(ExpectedLicensePath), Encoding.UTF8);

        if (!LinesEqual(actualLines, expectedLines))
        {
            Log.LogError($"License file content '{LicensePath}' doesn't match the expected license '{ExpectedLicensePath}'.");

src/Microsoft.DotNet.Arcade.Sdk/src/InstallDotNetCore.cs:98

  • When VersionsPropsPath is empty, the current error message prints a blank path, which makes it hard to diagnose what needs to be set. Consider an explicit message stating that VersionsPropsPath must be provided.
    src/Microsoft.DotNet.Helix/Sdk/InstallDotNetTool.cs:181
  • The log line uses DotnetPath, but the actual executable may be the literal "dotnet" (when DotnetPath is empty) or an absolutized path. This can produce misleading logs like Executing ... even though the task ran dotnet ....

Fixes the diagnostics flagged in the collapsed "Suppressed comments"
sections of the Copilot reviews, plus the path-inflation cases those
reviews missed:

- InstallDotNetTool: the "Executing" message printed DotnetPath, which is
  empty in the common case, so it reported a blank command while actually
  running "dotnet". Log the executable that is really invoked.
- InstallDotNetCore: an empty VersionsPropsPath produced "Unable to find
  translation file " with no path. Give it an explicit message instead.
- InstallDotNetCore: revert four messages that had been switched from the
  user-supplied property to the absolutized local. Per the migration
  guidance, "cannot find" diagnostics must echo the value the user wrote,
  not the resolved form. The "Executing:"/"Command:" lines keep the
  resolved path, since those report what was actually run.
- XHarnessTaskBase: the XML summary described Android only; it is the
  shared base for both Android and Apple.
Copilot AI review requested due to automatic review settings September 10, 2026 10:29
@ViktorHofer

Copy link
Copy Markdown
Member Author

Went back through the collapsed Suppressed comments sections of the Copilot reviews (they don't surface as resolvable threads). Six distinct findings; four addressed in 9ce7cc9, two declined with evidence.

Fixed

1. InstallDotNetTool.cs — log prints DotnetPath, task runs executable

Valid, and this PR made it worse. DotnetPath is empty in the common case, so the line reported a blank command while actually invoking dotnet. Now logs executable.

2. InstallDotNetCore.cs — empty VersionsPropsPath logs a blank path

Valid. The IsNullOrEmpty guard this PR added reused the "unable to find translation file" wording, which then printed nothing. Replaced with an explicit "must be specified" message.

3. XharnessTaskBase.cs — XML summary says "Android packages"

Valid; it is the shared base for Android and Apple. Corrected.

4. (not reported) Path inflation in InstallDotNetCore.cs

Auditing the above turned up four messages this PR had switched from the user-supplied property to the absolutized local, e.g. Unable to find global.json file '{globalJsonPath}'. That inverts the intended convention, so they are reverted to the raw properties. The Executing: / Command: lines deliberately keep the resolved path, since those report what was actually run rather than echoing user input.

Declined

5. DownloadFromResultsContainer.cs:85 — "Path.GetDirectoryName returns null for a bare filename, so Path.Combine throws"

The premise is incorrect. GetDirectoryName returns "", not null, for a bare filename — including the reviews own example:

file Path.GetDirectoryName Path.Combine(dest, ...)
results.xml '' C:\dest
sub/results.xml 'sub' C:\dest\sub
/ or C:\ or "" null throws

null only arises for a root path or the empty string, neither of which is a realistic DownloadFilesFromResults value. The line is also pre-existing and not part of this diff.

6. GetLicenseFilePath.cs:50 and ValidateLicense.cs:38/41 — "errors should log the resolved path"

Declining deliberately: this is the opposite of the guidance. Diagnostics are supposed to echo the value the user supplied, so that Cannot find 'app.manifest' doesn't turn into Cannot find 'C:\repo\app.manifest'. Logging the raw Directory / LicensePath here is correct, and applying this suggestion would introduce the defect that finding 4 above removes.

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.

Copilot review overview

🔵 Needs a closer look

Two confirmed edge-case bugs can still cause unhandled exceptions (PATH unset in LocateDotNet and null directory name handling in results download path creation).

Review tier: Lite
Findings: None

Suppressed comments (2)

Previously missed (2) — in code that hasn't changed since the last review.

src/Microsoft.DotNet.Arcade.Sdk/src/LocateDotNet.cs:38

  • If PATH is unset/empty in the task's environment, paths.Split(...) will throw a NullReferenceException. This should fail gracefully with a clear error since locating dotnet depends on PATH.
    src/Microsoft.DotNet.Helix/Sdk/DownloadFromResultsContainer.cs:81
  • Path.GetDirectoryName(file) can return null when the requested file has no directory component (e.g., "stdout.txt"), which would make Path.Combine(..., null) throw later in this loop and fail the download. Guard the directory creation so plain filenames work.

The previous commit fixed only the braces on lines this PR already
touched, which left the file internally inconsistent. These three were
pre-existing K&R and are the last ones in the file; it is now uniformly
Allman, per csharp_new_line_before_open_brace = all.

Whitespace-only: the file is token-identical to its parent once all
whitespace is stripped.
Copilot AI review requested due to automatic review settings September 10, 2026 10:42
TaskEnvironment.GetEnvironmentVariable is declared nullable, and the
multithreaded driver resolves it against a per-project environment
dictionary rather than the process block, so a missing PATH returns null
more readily than the previous Environment.GetEnvironmentVariable did.
paths.Split then threw a NullReferenceException.

Guard before the cache key is built so an empty PATH also reports this
rather than the misleading "unable to find dotnet with SDK version".
@ViktorHofer

Copy link
Copy Markdown
Member Author

Latest review's suppressed section had two findings — one real, one a repeat.

Fixed: LocateDotNet.cs — unset PATH

Correct. TaskEnvironment.GetEnvironmentVariable is declared string?, and the multithreaded driver implements it as _environmentVariables.TryGetValue(name, out value) ? value : null — a lookup against a per-project environment dictionary rather than the process block. So null is meaningfully more reachable here than with the Environment.GetEnvironmentVariable this line replaced, and paths.Split would have thrown NullReferenceException.

Guarded in c2e7325, placed before the cache key is constructed. Using IsNullOrEmpty rather than a null check also covers an empty PATH, which previously fell through RemoveEmptyEntries to zero candidates and reported the misleading "Unable to find dotnet with SDK version".

Declining again: DownloadFromResultsContainer.cs — null directory name

This is the same finding from the previous review, moved to a different line number. It remains incorrect, now against its own new example: Path.GetDirectoryName("stdout.txt") returns "", not null, so Path.Combine(dest, "") returns dest without throwing.

file Path.GetDirectoryName Path.Combine(dest, ...)
stdout.txt '' C:\dest
results.xml '' C:\dest
sub/results.xml 'sub' C:\dest\sub
/ or C:\ or "" null throws

null requires a root path or the empty string, neither of which is a plausible DownloadFilesFromResults entry. The line is also untouched by this PR — the only changes in that file are the attribute, the interface, the TaskEnvironment property, and two Directory.CreateDirectory call sites.

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.

Copilot review overview

🔵 Needs a closer look

LocateDotNet can crash with a NullReferenceException if PATH is unset/empty, and should instead log a clear error and return.

Review tier: Lite
Findings: None

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

src/Microsoft.DotNet.Arcade.Sdk/src/LocateDotNet.cs:38

  • TaskEnvironment.GetEnvironmentVariable("PATH") can return null/empty; the subsequent paths.Split(...) will throw NullReferenceException and hard-fail the task. Consider handling a missing PATH explicitly and logging a clear error instead of crashing.

Copilot AI review requested due to automatic review settings September 10, 2026 10:48

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.

Copilot review overview

🔵 Needs a closer look

GenerateChecksums now calls TaskEnvironment.GetAbsolutePath(item.ItemSpec) without guarding against an empty item spec, which can turn the previous “file missing” error path into an exception-based failure.

Review tier: Lite
Findings: None

Suppressed comments (2)

Previously missed (2) — in code that hasn't changed since the last review.

src/Microsoft.DotNet.Arcade.Sdk/src/GenerateChecksums.cs:41

  • TaskEnvironment.GetAbsolutePath(item.ItemSpec) throws for an empty item spec, which changes the failure mode from the existing "file does not exist" error into an exception-based failure. Since Items is user-supplied, it’s safer to keep the explicit missing-file error path for empty specs too.
    src/Microsoft.DotNet.Helix/Sdk/InstallDotNetTool.cs:119
  • version is normalized to lower-case but ToolPath is still built with Version. On case-sensitive file systems this can defeat the "same tool/version" deduplication (mutex key and directory) for semantically identical versions differing only by case, and it makes the lower-casing logic easy to misread as dead code.

…cksums

File.Exists returned false for an empty item spec, so the task reported
"The file '' does not exist." GetAbsolutePath throws instead, and while
the surrounding try/catch keeps that from crashing the build, it replaced
the diagnostic with "The value cannot be an empty string. (Parameter
'path')". Guard so the original error path is kept.

Items is ITaskItem[], so [Required] validates only that the collection is
non-empty; an individual ItemSpec can still be empty. The remaining
path inputs across this PR are [Required] scalars, which MSBuild rejects
before Execute runs.
Copilot AI review requested due to automatic review settings September 10, 2026 10:57
@ViktorHofer

Copy link
Copy Markdown
Member Author

Two findings this round, both against the current head.

Fixed: GenerateChecksums.cs — empty item spec

Correct, and a genuine regression from this PR. main probed File.Exists(item.ItemSpec), which returns false for an empty spec and produced The file '' does not exist. Routing through GetAbsolutePath throws instead. The surrounding try/catch means it is not an unhandled crash as described, but it does swap a clear diagnostic for The value cannot be an empty string. (Parameter 'path'). Guarded in c551815.

This one is reachable precisely because Items is ITaskItem[]: [Required] validates that the collection is non-empty, not that each ItemSpec is.

Since this is the fourth report of this class, I swept every GetAbsolutePath call site in the PR rather than wait for them one at a time — 39 sites:

  • 18 are [Required] scalar strings, which MSBuild rejects as empty before Execute runs
  • 6 were already guarded (DotnetPath, WorkingDirectory, TmpDir, plus the three fixed in dc205c6)
  • the rest derive from already-resolved values or literals
  • GetAssemblyFullName takes metadata that can be empty, but is not a regression: AssemblyName.GetAssemblyName("") on main threw ArgumentException just the same

GenerateChecksums was the only remaining case.

Declining: InstallDotNetTool.cs — Version vs lower-cased version

This is unchanged from main, which has the identical pair:

var version = Version.ToLowerInvariant();
ToolPath = Path.Combine(DestinationPath, Name, Version);
string versionInstallPath = Path.Combine(ToolPath, ".store", Name.ToLowerInvariant(), version);

This PR only replaced DestinationPath with its absolutized form. The asymmetry is also deliberate rather than an oversight: versionInstallPath must match the .store/<id>/<version> layout that dotnet tool install creates, and that layout lower-cases both; ToolPath is the --tool-path directory we choose ourselves, so it keeps the caller's casing. Changing it would alter on-disk layout for existing consumers, which is out of scope for a mechanical migration.

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.

Copilot review overview

🔵 Needs a closer look

The changes are broad and concurrency-sensitive (task routing, environment/path scoping, and process invocation), so a final human review is advisable even though the diff looks internally consistent.

Review tier: Lite
Findings: None

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.

Copilot review overview

🟡 Changes recommended

Existing InstallDotNetTool tests use Windows-only path literals and will fail on non-Windows hosts after path resolution.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 High severity

New issues introduced by this change (1)
Severity Finding
High severity src/​Microsoft.DotNet.Helix/​Sdk/​InstallDotNetTool.cs — This makes the existing cross-platform InstallDotNetToolTests fail on non-Windows hosts. The…
Suppressed comments (1)

src/Microsoft.DotNet.Helix/Sdk/InstallDotNetTool.cs:180

  • The explicit-path test sets DotnetPath to D:\dotnet\dotnet.exe on every OS and configures the command mock to expect that exact string. On Unix, this new resolution treats it as relative and passes <project>/D:\dotnet\dotnet.exe, so InstallsToolWithExtraParamsSuccessfully no longer matches the mock. Please use a host-native absolute executable path in that test or compute the expected value through the task environment.
        // A bare "dotnet" is resolved through PATH by the process launcher and must stay
        // unresolved; only an explicitly supplied path is made absolute.
        var executable = string.IsNullOrEmpty(DotnetPath) ? "dotnet" : (string)TaskEnvironment.GetAbsolutePath(DotnetPath);

The task now resolves DestinationPath and DotnetPath through
TaskEnvironment. The fixture used "C:\dotnet_tools" and
"D:\dotnet\dotnet.exe", which are absolute only on Windows; on Unix
neither is rooted, so resolution prefixes the project directory and the
ToolPath assertions, the --tool-path argument and the ICommandFactory
mock expectation all stop matching.

Build the paths from Path.GetTempPath() instead, which is absolute on
every host, so the resolved value is identical to the literal. Nothing
is written to these paths; the file system is mocked.
Copilot AI review requested due to automatic review settings September 10, 2026 11:16
@ViktorHofer

Copy link
Copy Markdown
Member Author

Good catch, and the most consequential finding so far — fixed in c263858.

InstallDotNetToolTests used C:\dotnet_tools and D:\dotnet\dotnet.exe. Those are absolute only on Windows; on Unix neither is rooted, so once the task resolves DestinationPath and DotnetPath the values get prefixed with the project directory while s_installedPath and the ICommandFactory mock expectation keep the bare literal. That breaks three things at once on non-Windows: the ToolPath assertions, the --tool-path argument, and the command-factory match (which would hand back a null command rather than fail cleanly).

Both are now built from Path.GetTempPath(), which is absolute on every host, so the resolved value is identical to the literal. Nothing is written to those paths — the file system is mocked throughout.

Verified 304/304 green on Windows, including all 6 InstallDotNetToolTests; the Linux and macOS legs will confirm the other direction.

I also swept for the same class rather than handle it one report at a time: across both changed files and the full Sdk.Tests / Arcade.Sdk test projects, there are no other drive-letter or backslash path literals. This was the only occurrence.

Worth noting for the remaining subsets of this migration, since it generalizes beyond this PR: absolutizing a task input turns any Windows-shaped test literal into a silent cross-platform failure, because such a literal is valid but relative on Unix rather than an error. Test fixtures for migrated tasks need host-native paths.

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.

Copilot review overview

🟡 Changes recommended

The PATH-based DotNetTool fallback is incorrectly converted into a project-relative path.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review tier: Balanced
Findings: 1 High severity

New issues introduced by this change (1)
Severity Finding
High severity src/​Microsoft.DotNet.Helix/​Sdk/​InstallDotNetTool.cs — When Arcade's repo-local .dotnet directory is absent, RepoLayout.props:18-22 intentionally sets…
Issues resolved since last review (1)
Severity Finding
High severity src/​Microsoft.DotNet.Helix/​Sdk/​InstallDotNetTool.cs — This makes the existing cross-platform InstallDotNetToolTests fail on non-Windows hosts. The… View resolved comment

RepoLayout.props clears DotNetRoot when the repo-local .NET install is
absent ("Let the exec task find dotnet on PATH"), which leaves DotNetTool
as a bare "dotnet"/"dotnet.exe". XHarnessRunner.targets forwards that as
DotnetPath, so it is non-empty and the previous change absolutized it into
<project>/dotnet.exe, breaking XHarness tool installation in that
supported fallback configuration.

Only absolutize when the value carries a directory component. A bare
executable name is passed through so the process launcher resolves it on
PATH, which is also how Tests.targets treats DotNetTool (it guards with
IsPathRooted before deriving a host directory from it).

Adds a regression test; without the fix it fails with a
NullReferenceException, because the command factory never matches the
absolutized name.
Copilot AI review requested due to automatic review settings September 10, 2026 11:58
@ViktorHofer

Copy link
Copy Markdown
Member Author

Confirmed and fixed in d5759ec. This was a real regression in a supported configuration, and my own code comment claimed to handle the case it actually got wrong.

RepoLayout.props clears DotNetRoot when the repo-local install is missing, with the comment "Let the exec task find dotnet on PATH":

<DotNetRoot Condition="!Exists($(DotNetRoot))"/>
<DotNetTool Condition="'$(OS)' == 'Windows_NT'">$(DotNetRoot)dotnet.exe</DotNetTool>

so DotNetTool becomes a bare dotnet.exe, and XHarnessRunner.targets:38 forwards it as DotnetPath. That value is non-empty, so my IsNullOrEmpty check missed it and it became <project>/dotnet.exe. I had only considered the unset case, not the "set to a PATH-resolved name" case.

The fix absolutizes only when the value carries a directory component:

if (string.IsNullOrEmpty(DotnetPath))            executable = "dotnet";
else if (string.IsNullOrEmpty(Path.GetDirectoryName(DotnetPath))) executable = DotnetPath;
else                                             executable = TaskEnvironment.GetAbsolutePath(DotnetPath);

This matches how the rest of the repo treats the property — Tests.targets:55 guards with IsPathRooted('$(DotNetTool)') before deriving a host directory from it, for exactly the same reason.

Added BareExecutableNameIsNotResolvedToAPath. As a negative control I ran it against the unfixed code first: it fails with a NullReferenceException at InstallDotNetTool.cs:193, because the command factory never matches the absolutized name and hands back a null command. Suite is 305/305 with the fix.

I also swept for the same class rather than wait for another report. XHarnessRunner.targets is the only place a migrated task receives $(DotNetTool); InstallDotNetCore.DotNetPath is a directory passed to the install script rather than an executable, and is resolved downstream on the combined runtime path. This was the only occurrence.

Generalizing for the remaining subsets: a task input that names an executable must not be absolutized unconditionally, because a bare name is a legitimate value meaning "resolve on PATH". That is a distinct hazard from the empty-path one, since the value is non-empty and looks perfectly valid.

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.

Copilot review overview

🟢 Approval recommended

The migration consistently isolates project-scoped state, preserves intentional exclusions, and includes targeted regression coverage.

Review tier: Balanced
Findings: None

Issues resolved since last review (1)
Severity Finding
High severity src/​Microsoft.DotNet.Helix/​Sdk/​InstallDotNetTool.cs — When Arcade's repo-local .dotnet directory is absent, RepoLayout.props:18-22 intentionally sets… View resolved comment

akoeplinger
akoeplinger previously approved these changes Sep 10, 2026
…sPath errors

The comment on SendHelixJob claimed the task cannot be multithreaded
because JobDefinition reads BUILD_REPOSITORY_NAME, BUILD_SOURCEBRANCH,
SYSTEM_TEAMPROJECT and BUILD_REASON from Environment. Those are Azure
Pipelines build-level variables, set once by the agent for the whole
process, so they do not vary per project and no job can be tagged with
another project's metadata. The real reason to hold this task back is
that the JobSender and HelixApi stack has not been audited for shared
mutable state.

Also replaces "translation file" with wording that matches the
neighbouring errors, which already refer to the properties defined in
VersionsPropsPath.

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.

Copilot review overview

🔵 Needs a closer look

Cross-assembly task routing and concurrent path/process semantics warrant final human validation.

Review tier: Balanced
Findings: None

@ViktorHofer
ViktorHofer merged commit db8d7a0 into dotnet:main Sep 10, 2026
17 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 11, 2026
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