<# .SYNOPSIS Build and package PowerToys (CmdPal and installer) for a specific platform and configuration LOCALLY. .DESCRIPTION This script automates the end-to-end build and packaging process for PowerToys, including: - Restoring and building all necessary solutions (CmdPal, BugReportTool, etc.) - Cleaning up old output - Signing generated .msix packages - Building the WiX v5 (VNext) MSI and bootstrapper installers It is designed to work in local development. The cert used to sign the packages is generated by .PARAMETER Platform Specifies the target platform for the build (e.g., 'arm64', 'x64'). Default is 'x64'. .PARAMETER Configuration Specifies the build configuration (e.g., 'Debug', 'Release'). Default is 'Release'. .PARAMETER PerUser Specifies whether to build a per-user installer (true) or machine-wide installer (false). Default is true (per-user). .EXAMPLE .\build-installer.ps1 Runs the installer build pipeline for x64 Release. .EXAMPLE .\build-installer.ps1 -Platform x64 -Configuration Release Runs the pipeline for x64 Release. .EXAMPLE .\build-installer.ps1 -Platform x64 -Configuration Release -PerUser false Runs the pipeline for x64 Release with machine-wide installer. .NOTES - Make sure to run this script from a Developer PowerShell (e.g., VS2022 Developer PowerShell). - Generated MSIX files will be signed using cert-sign-package.ps1. - This script will clean previous outputs under the build directories and installer directory (except *.exe files). - First time run need admin permission to trust the certificate. - The built installer will be placed under: installer/PowerToysSetupVNext/[Platform]/[Configuration]/User[Machine]Setup relative to the solution root directory. - To run the full installation in other machines, call "./cert-management.ps1" to export the cert used to sign the packages. And trust the cert in the target machine. #> param ( [string]$Platform = '', [string]$Configuration = 'Release', [string]$PerUser = 'true' ) # Ensure helpers are available . "$PSScriptRoot\build-common.ps1" # Initialize Visual Studio dev environment if (-not (Ensure-VsDevEnvironment)) { exit 1 } # Auto-detect platform when not provided if (-not $Platform -or $Platform -eq '') { try { $Platform = Get-DefaultPlatform Write-Host ("[AUTO-PLATFORM] Detected platform: {0}" -f $Platform) } catch { Write-Warning "Failed to auto-detect platform; defaulting to x64" $Platform = 'x64' } } # Find the PowerToys repository root automatically $scriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition $repoRoot = $scriptDir # Navigate up from the script location to find the repo root # Script is typically in tools\build, so go up two levels while ($repoRoot -and -not (Test-Path (Join-Path $repoRoot "PowerToys.sln"))) { $parentDir = Split-Path -Parent $repoRoot if ($parentDir -eq $repoRoot) { # Reached the root of the drive, PowerToys.sln not found Write-Error "Could not find PowerToys repository root. Make sure this script is in the PowerToys repository." exit 1 } $repoRoot = $parentDir } if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot "PowerToys.sln"))) { Write-Error "Could not locate PowerToys.sln. Please ensure this script is run from within the PowerToys repository." exit 1 } Write-Host "PowerToys repository root detected: $repoRoot" # WiX v5 projects use WixToolset.Sdk via NuGet/MSBuild; no separate WiX installation is required. Write-Host ("[PIPELINE] Start | Platform={0} Configuration={1} PerUser={2}" -f $Platform, $Configuration, $PerUser) Write-Host '' $cmdpalOutputPath = Join-Path $repoRoot "$Platform\$Configuration\WinUI3Apps\CmdPal" if (Test-Path $cmdpalOutputPath) { Write-Host "[CLEAN] Removing previous output: $cmdpalOutputPath" Remove-Item $cmdpalOutputPath -Recurse -Force -ErrorAction Ignore } $commonArgs = '/p:CIBuild=true' # No local projects found (or continuing) - build full solution and tools RestoreThenBuild 'PowerToys.sln' $commonArgs $Platform $Configuration $msixSearchRoot = Join-Path $repoRoot "$Platform\$Configuration" $msixFiles = Get-ChildItem -Path $msixSearchRoot -Recurse -Filter *.msix | Select-Object -ExpandProperty FullName if ($msixFiles.Count) { Write-Host ("[SIGN] .msix file(s): {0}" -f ($msixFiles -join '; ')) & (Join-Path $PSScriptRoot "cert-sign-package.ps1") -TargetPaths $msixFiles } else { Write-Warning "[SIGN] No .msix files found in $msixSearchRoot" } # Generate DSC manifest files Write-Host '[DSC] Generating DSC manifest files...' $dscScriptPath = Join-Path $repoRoot '.\tools\build\generate-dsc-manifests.ps1' if (Test-Path $dscScriptPath) { & $dscScriptPath -BuildPlatform $Platform -BuildConfiguration $Configuration -RepoRoot $repoRoot if ($LASTEXITCODE -ne 0) { Write-Error "DSC manifest generation failed with exit code $LASTEXITCODE" exit 1 } Write-Host '[DSC] DSC manifest files generated successfully' } else { Write-Warning "[DSC] DSC manifest generator script not found at: $dscScriptPath" } RestoreThenBuild 'tools\BugReportTool\BugReportTool.sln' $commonArgs $Platform $Configuration RestoreThenBuild 'tools\StylesReportTool\StylesReportTool.sln' $commonArgs $Platform $Configuration Write-Host '[CLEAN] installer (keep *.exe)' Push-Location $repoRoot try { git clean -xfd -e '*.exe' -- .\installer\ | Out-Null } finally { Pop-Location } RunMSBuild 'installer\PowerToysSetup.sln' "$commonArgs /t:restore /p:RestorePackagesConfig=true" $Platform $Configuration RunMSBuild 'installer\PowerToysSetup.sln' "$commonArgs /m /t:PowerToysInstallerVNext /p:PerUser=$PerUser" $Platform $Configuration RunMSBuild 'installer\PowerToysSetup.sln' "$commonArgs /m /t:PowerToysBootstrapperVNext /p:PerUser=$PerUser" $Platform $Configuration Write-Host '[PIPELINE] Completed'