Skip to content

fix: use nested Join-Path for PowerShell 5.1 compatibility#593

Merged
danielmeppiel merged 3 commits intomicrosoft:mainfrom
edenfunf:fix/powershell-51-join-path-compat
Apr 6, 2026
Merged

fix: use nested Join-Path for PowerShell 5.1 compatibility#593
danielmeppiel merged 3 commits intomicrosoft:mainfrom
edenfunf:fix/powershell-51-join-path-compat

Conversation

@edenfunf
Copy link
Copy Markdown
Contributor

@edenfunf edenfunf commented Apr 6, 2026

Description

Fixes #592

apm runtime setup fails immediately on Windows with the default PowerShell 5.1 because the setup scripts call Join-Path with three or more positional path segments -- a syntax that requires PowerShell 6.0+.

Join-Path : A positional parameter cannot be found that accepts argument 'runtimes'.
At setup-common.ps1:27
+     $runtimeDir = Join-Path $env:USERPROFILE ".apm" "runtimes"

Windows ships with PowerShell 5.1 as the default shell. Users who have not separately installed PowerShell 7+ cannot set up any runtime.

The fix replaces every multi-segment Join-Path call with nested two-argument calls, which are compatible with both PowerShell 5.1 and 7+:

# Before (PS 6+ only)
$runtimeDir = Join-Path $env:USERPROFILE ".apm" "runtimes"

# After (PS 5.1+)
$runtimeDir = Join-Path (Join-Path $env:USERPROFILE ".apm") "runtimes"

Type of change

  • Bug fix

Testing

  • Tested locally
  • All existing tests pass

Confirmed on Windows 11 Pro with PowerShell 5.1.26100.x:

  • Reproduced the error using the original code (Join-Path A B C raises PositionalParameterNotFound on PS 5.1)
  • Verified the fix produces the correct path with nested calls
  • Full unit suite: 3614 tests passed

PowerShell 5.1 (Windows default) only accepts two positional arguments
for Join-Path. Calls with 3+ segments (e.g. Join-Path A B C) require
PowerShell 6+, causing runtime setup to abort immediately on standard
Windows installations.

Replace all multi-argument Join-Path calls with nested two-argument
calls that work on both PowerShell 5.1 and 7+.

Fixes microsoft#592
@edenfunf edenfunf requested a review from danielmeppiel as a code owner April 6, 2026 11:29
@danielmeppiel danielmeppiel merged commit 146fe50 into microsoft:main Apr 6, 2026
4 checks passed
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.

[BUG] apm runtime setup fails on Windows PowerShell 5.1: Join-Path positional parameter error

2 participants