Skip to content

Commit bc86a9b

Browse files
fix(bootstrap): -InstallWinAppSdk as [switch] not [Nullable[bool]]
`[Nullable[bool]]$Foo = $null` doesn't get PowerShell's switch-style parameter binding — passing a bare `-InstallWinAppSdk` errors with "Missing an argument for parameter 'InstallWinAppSdk'." which is what the bootstrap.yml run hit. Tri-state via nullable bool would have required every caller (including the .EXAMPLE block in the doc header) to write `-InstallWinAppSdk:$true`, which is a footgun. Refactor to two mutually-exclusive [switch] parameters: -InstallWinAppSdk force install non-interactively (CI / automation) -NoWinAppSdk skip the prompt silently (neither) prompt the user (default no) Mutual exclusion checked at the top of the script (early exit with a clear error before any side effects). The "default no, prompt" behavior is preserved for interactive dev runs. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent e5cf892 commit bc86a9b

1 file changed

Lines changed: 24 additions & 24 deletions

File tree

bootstrap.ps1

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
Build configuration for the CLI nupkg. Default: Release.
2424
2525
.PARAMETER InstallWinAppSdk
26-
Tri-state Windows App Runtime 2.0 install. When unspecified (default),
27-
prompt interactively (default no). Pass -InstallWinAppSdk to force-install
28-
non-interactively (useful for CI / one-shot dev-box setup); pass
29-
-InstallWinAppSdk:$false to skip the prompt silently. The framework
30-
defaults to self-contained, so the runtime is only required for
31-
framework-dependent deployment.
26+
Install the Windows App Runtime 2.0 via winget without prompting.
27+
Useful for CI / one-shot dev-box automation. Mutually exclusive with
28+
-NoWinAppSdk. The framework defaults to self-contained, so the
29+
runtime is only required for framework-dependent deployment.
30+
31+
.PARAMETER NoWinAppSdk
32+
Skip the Windows App Runtime 2.0 prompt silently. Useful for
33+
non-interactive scripts that explicitly don't want the runtime
34+
installed. Mutually exclusive with -InstallWinAppSdk.
3235
3336
.EXAMPLE
3437
./bootstrap.ps1
@@ -48,15 +51,16 @@ param(
4851
[switch]$SkipPlugin,
4952
[switch]$SkipMurInstall,
5053
[string]$Configuration = 'Release',
51-
# Windows App SDK runtime install: tri-state. When unspecified, prompt
52-
# interactively (default no) since the framework defaults to
53-
# WindowsAppSDKSelfContained=true and the machine runtime is only needed
54-
# for framework-dependent deployment. Pass -InstallWinAppSdk to force-
55-
# install non-interactively; pass -InstallWinAppSdk:$false to skip the
56-
# prompt and continue.
57-
[Nullable[bool]]$InstallWinAppSdk = $null
54+
[switch]$InstallWinAppSdk,
55+
[switch]$NoWinAppSdk
5856
)
5957

58+
if ($InstallWinAppSdk -and $NoWinAppSdk) {
59+
Write-Host ''
60+
Write-Host "ERROR: -InstallWinAppSdk and -NoWinAppSdk are mutually exclusive." -ForegroundColor Red
61+
exit 1
62+
}
63+
6064
$ErrorActionPreference = 'Stop'
6165
$repoRoot = $PSScriptRoot
6266
Set-Location $repoRoot
@@ -157,12 +161,10 @@ function Test-WindowsAppRuntime20 {
157161
}
158162

159163
if (-not (Test-WindowsAppRuntime20)) {
160-
$shouldInstall = $false
161-
if ($null -ne $InstallWinAppSdk) {
162-
$shouldInstall = [bool]$InstallWinAppSdk
163-
if (-not $shouldInstall) {
164-
Write-Host ' [skip] Windows App Runtime 2.0 not installed (skipped per -InstallWinAppSdk:$false).' -ForegroundColor Yellow
165-
}
164+
if ($InstallWinAppSdk) {
165+
Install-WithWinget -Id 'Microsoft.WindowsAppRuntime.2.0' -Reason 'Windows App Runtime 2.0'
166+
} elseif ($NoWinAppSdk) {
167+
Write-Host ' [skip] Windows App Runtime 2.0 not installed (skipped per -NoWinAppSdk).' -ForegroundColor Yellow
166168
} else {
167169
Write-Host ''
168170
Write-Host ' Windows App Runtime 2.0 is not installed on this machine.' -ForegroundColor Yellow
@@ -171,14 +173,12 @@ if (-not (Test-WindowsAppRuntime20)) {
171173
Write-Host ' deployment (smaller per-app output, faster builds) when you override'
172174
Write-Host ' WindowsAppSDKSelfContained=false in a consuming project.'
173175
$answer = Read-Host ' Install Windows App Runtime 2.0 via winget now? [y/N]'
174-
$shouldInstall = ($answer -match '^[Yy]')
175-
if (-not $shouldInstall) {
176+
if ($answer -match '^[Yy]') {
177+
Install-WithWinget -Id 'Microsoft.WindowsAppRuntime.2.0' -Reason 'Windows App Runtime 2.0'
178+
} else {
176179
Write-Host " Skipped. Re-run later with: winget install Microsoft.WindowsAppRuntime.2.0" -ForegroundColor Cyan
177180
}
178181
}
179-
if ($shouldInstall) {
180-
Install-WithWinget -Id 'Microsoft.WindowsAppRuntime.2.0' -Reason 'Windows App Runtime 2.0'
181-
}
182182
} else {
183183
Write-Ok 'Windows App Runtime 2.0 installed'
184184
}

0 commit comments

Comments
 (0)