Files
XplorePlane/XP.Installer/Setup/Scripts/Generate-ReleaseFilesWxs.ps1
T
2026-08-12 18:07:22 +08:00

56 lines
1.8 KiB
PowerShell

[CmdletBinding()]
param(
[string]$ReleaseFilesRoot = (Join-Path $PSScriptRoot '..\..\..\ReleaseFiles'),
[string]$OutputFile = (Join-Path $PSScriptRoot '..\BundleInstaller\ReleaseFiles.generated.wxs'),
[string]$HeatPath = ''
)
$ErrorActionPreference = 'Stop'
$ReleaseFilesRoot = [System.IO.Path]::GetFullPath($ReleaseFilesRoot)
$OutputFile = [System.IO.Path]::GetFullPath($OutputFile)
if (-not (Test-Path -LiteralPath $ReleaseFilesRoot -PathType Container)) {
throw "Release files directory does not exist: $ReleaseFilesRoot"
}
if ([string]::IsNullOrWhiteSpace($HeatPath)) {
$heatCommand = Get-Command heat.exe -ErrorAction SilentlyContinue
if ($heatCommand) {
$HeatPath = $heatCommand.Source
} elseif ($env:WIX -and (Test-Path -LiteralPath (Join-Path $env:WIX 'heat.exe'))) {
$HeatPath = Join-Path $env:WIX 'heat.exe'
} else {
$defaultHeat = 'C:\Program Files (x86)\WiX Toolset v3.14\bin\heat.exe'
if (Test-Path -LiteralPath $defaultHeat) {
$HeatPath = $defaultHeat
} else {
throw 'heat.exe was not found. Install WiX Toolset 3.x or pass -HeatPath.'
}
}
}
$outputDirectory = Split-Path -Parent $OutputFile
New-Item -ItemType Directory -Path $outputDirectory -Force | Out-Null
# -ag lets WiX derive component GUIDs at compile time. Do not use -gg here:
# generating new GUIDs on every run would break MSI upgrade/component identity.
$heatArguments = @(
'dir', $ReleaseFilesRoot,
'-cg', 'ReleaseFilesComponents',
'-dr', 'APPLICATIONFOLDER',
'-ag',
'-srd',
'-sreg',
'-scom',
'-var', 'var.ReleaseFilesSource',
'-nologo',
'-out', $OutputFile
)
& $HeatPath @heatArguments
if ($LASTEXITCODE -ne 0) {
throw "heat.exe failed with exit code $LASTEXITCODE."
}
Write-Host "Generated: $OutputFile"