From 6ed23472147d8b435f394dc50613383070daee22 Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 1 Aug 2026 19:58:13 +0100 Subject: [PATCH] Refactor Windows MSI build script to improve argument handling - Introduced a new function, ConvertTo-WixVersion, to standardize version formatting for the MSI build process. - Updated the PowerShell script to use arrays for passing arguments to the candle and light commands, enhancing readability and reliability. - Ensured proper handling of paths with spaces by quoting arguments appropriately. --- scripts/build-windows-msi.ps1 | 39 +++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/scripts/build-windows-msi.ps1 b/scripts/build-windows-msi.ps1 index 9ebc716..ca5e34c 100644 --- a/scripts/build-windows-msi.ps1 +++ b/scripts/build-windows-msi.ps1 @@ -44,20 +44,41 @@ if (Test-Path $workDir) { } New-Item -ItemType Directory -Path $workDir | Out-Null +function ConvertTo-WixVersion([string]$rawVersion) { + $parts = $rawVersion.Split('.') + while ($parts.Count -lt 4) { + $parts += '0' + } + return ($parts[0..3] -join '.') +} + $candle = Find-WixTool "candle" $light = Find-WixTool "light" -& $candle ` - -nologo ` - -out $wixObj ` - -dVersion=$Version ` - -dSetupExe=$SetupExe ` - $wxsPath +$wixVersion = ConvertTo-WixVersion $Version +$setupExePath = (Resolve-Path -LiteralPath $SetupExe).Path -& $light ` - -nologo ` - -out $OutputMsi ` +# Quote -d defines so PowerShell passes them as single args to candle.exe. +# Unquoted -dVersion=$Version is parsed incorrectly; paths with spaces also break. +$candleArgs = @( + '-nologo' + '-out' $wixObj + "-dVersion=$wixVersion" + "-dSetupExe=$setupExePath" + $wxsPath +) + +& $candle @candleArgs + +$lightArgs = @( + '-nologo' + '-out' + $OutputMsi + $wixObj +) + +& $light @lightArgs if (-not (Test-Path $OutputMsi)) { throw "MSI was not created at $OutputMsi"