|
| 1 | +[CmdletBinding()] |
| 2 | +param( |
| 3 | + [ValidateSet("Debug", "Release")] |
| 4 | + [string]$Configuration = "Release", |
| 5 | + |
| 6 | + [ValidateSet("x86")] |
| 7 | + [string]$Platform = "x86" |
| 8 | +) |
| 9 | + |
| 10 | +$ErrorActionPreference = "Stop" |
| 11 | + |
| 12 | +Write-Host ("Installer build started {0:yyyy.MM.dd HH:mm:ss}" -f (Get-Date)) |
| 13 | + |
| 14 | +$scriptRoot = $PSScriptRoot |
| 15 | +$repoRoot = [System.IO.Path]::GetFullPath((Join-Path $scriptRoot "..")) |
| 16 | +$appProject = Join-Path $repoRoot "src\SecondaryClick\SecondaryClick.csproj" |
| 17 | +$installerProject = Join-Path $repoRoot "src\SecondaryClick.Installer\SecondaryClick.Installer.wixproj" |
| 18 | + |
| 19 | +$msbuildExe = $null |
| 20 | +$vsWhereCmd = Get-Command vswhere.exe -ErrorAction SilentlyContinue |
| 21 | +if (-not $vsWhereCmd) { |
| 22 | + throw "vswhere.exe not found in PATH. Please install Visual Studio/Build Tools and ensure vswhere is available." |
| 23 | +} |
| 24 | + |
| 25 | +$msbuildFromVsWhere = & $vsWhereCmd.Source -latest -products * -requires Microsoft.Component.MSBuild -find "MSBuild\**\Bin\MSBuild.exe" | Select-Object -First 1 |
| 26 | +if (-not [string]::IsNullOrWhiteSpace($msbuildFromVsWhere) -and (Test-Path $msbuildFromVsWhere)) { |
| 27 | + $msbuildExe = $msbuildFromVsWhere |
| 28 | +} |
| 29 | + |
| 30 | +if (-not $msbuildExe) { |
| 31 | + throw "MSBuild.exe not found via vswhere. Please install Visual Studio Build Tools with MSBuild component." |
| 32 | +} |
| 33 | + |
| 34 | +if ([string]::IsNullOrWhiteSpace($env:WIX)) { |
| 35 | + throw "WIX environment variable is not set. This project's PreBuildEvent uses $(WIX)bin\heat." |
| 36 | +} |
| 37 | + |
| 38 | +if (-not (Test-Path $appProject)) { |
| 39 | + throw "App project not found: $appProject" |
| 40 | +} |
| 41 | + |
| 42 | +if (-not (Test-Path $installerProject)) { |
| 43 | + throw "Installer project not found: $installerProject" |
| 44 | +} |
| 45 | + |
| 46 | +Set-Location $repoRoot |
| 47 | + |
| 48 | +dotnet restore $appProject |
| 49 | +if ($LASTEXITCODE -ne 0) { |
| 50 | + throw "dotnet restore failed for: $appProject" |
| 51 | +} |
| 52 | + |
| 53 | +& $msbuildExe $installerProject /t:Build /p:Configuration=$Configuration /p:Platform=$Platform /nologo |
| 54 | +if ($LASTEXITCODE -ne 0) { |
| 55 | + throw "Installer build failed: $installerProject" |
| 56 | +} |
| 57 | + |
| 58 | +$buildDir = Join-Path $repoRoot "build" |
| 59 | +$msiPath = Join-Path $buildDir "SecondaryClick.msi" |
| 60 | +$versionedMsi = Get-ChildItem $buildDir -Filter "SecondaryClick-*.msi" -ErrorAction SilentlyContinue | Sort-Object LastWriteTime -Descending | Select-Object -First 1 |
| 61 | + |
| 62 | +if ((-not (Test-Path $msiPath)) -and (-not $versionedMsi)) { |
| 63 | + Write-Warning "Build finished but no MSI found in: $buildDir" |
| 64 | +} |
| 65 | + |
| 66 | +Write-Host "Installer build completed." |
0 commit comments