Refactor Windows MSI build script to improve argument handling
All checks were successful
farmcontrol/farmcontrol-server/pipeline/head This commit looks good

- 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.
This commit is contained in:
Tom Butcher 2026-08-01 19:58:13 +01:00
parent 503fd6e0de
commit 6ed2347214

View File

@ -44,20 +44,41 @@ if (Test-Path $workDir) {
} }
New-Item -ItemType Directory -Path $workDir | Out-Null 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" $candle = Find-WixTool "candle"
$light = Find-WixTool "light" $light = Find-WixTool "light"
& $candle ` $wixVersion = ConvertTo-WixVersion $Version
-nologo ` $setupExePath = (Resolve-Path -LiteralPath $SetupExe).Path
-out $wixObj `
-dVersion=$Version `
-dSetupExe=$SetupExe `
$wxsPath
& $light ` # Quote -d defines so PowerShell passes them as single args to candle.exe.
-nologo ` # Unquoted -dVersion=$Version is parsed incorrectly; paths with spaces also break.
-out $OutputMsi ` $candleArgs = @(
'-nologo'
'-out'
$wixObj $wixObj
"-dVersion=$wixVersion"
"-dSetupExe=$setupExePath"
$wxsPath
)
& $candle @candleArgs
$lightArgs = @(
'-nologo'
'-out'
$OutputMsi
$wixObj
)
& $light @lightArgs
if (-not (Test-Path $OutputMsi)) { if (-not (Test-Path $OutputMsi)) {
throw "MSI was not created at $OutputMsi" throw "MSI was not created at $OutputMsi"