farmcontrol-server/scripts/build-windows-msi.ps1
Tom Butcher 6ed2347214
All checks were successful
farmcontrol/farmcontrol-server/pipeline/head This commit looks good
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.
2026-08-01 19:58:13 +01:00

88 lines
2.0 KiB
PowerShell

param(
[Parameter(Mandatory = $true)]
[string]$SetupExe,
[Parameter(Mandatory = $true)]
[string]$OutputMsi,
[Parameter(Mandatory = $true)]
[string]$Version
)
$ErrorActionPreference = "Stop"
function Find-WixTool($toolName) {
$command = Get-Command $toolName -ErrorAction SilentlyContinue
if ($command) {
return $command.Source
}
$searchRoots = @(
"${env:ProgramFiles(x86)}\WiX Toolset v3.14\bin",
"${env:ProgramFiles(x86)}\WiX Toolset v3.11\bin",
"${env:ProgramFiles}\WiX Toolset v3.14\bin",
"${env:ProgramFiles}\WiX Toolset v3.11\bin"
)
foreach ($root in $searchRoots) {
$candidate = Join-Path $root "$toolName.exe"
if (Test-Path $candidate) {
return $candidate
}
}
throw "Could not find $toolName. Install WiX Toolset v3.11 or v3.14 on the Windows build agent."
}
$rootDir = Split-Path -Parent $PSScriptRoot
$wxsPath = Join-Path $rootDir "packaging/windows/farmcontrol-server.wxs"
$workDir = Join-Path $env:TEMP "farmcontrol-server-msi"
$wixObj = Join-Path $workDir "farmcontrol-server.wixobj"
if (Test-Path $workDir) {
Remove-Item $workDir -Recurse -Force
}
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"
$wixVersion = ConvertTo-WixVersion $Version
$setupExePath = (Resolve-Path -LiteralPath $SetupExe).Path
# 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"
}
Write-Host "Created MSI at $OutputMsi"