mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-15 03:07:56 +01:00
Merge remote-tracking branch 'origin/dev/vanzue/fix-local-installer-build' into dev/vanzue/cmdpal-pt
This commit is contained in:
@@ -41,16 +41,20 @@ param (
|
||||
[string]$Platform = 'x64',
|
||||
[string]$Configuration = 'Release',
|
||||
[string]$PerUser = 'true',
|
||||
[string]$Version,
|
||||
[switch]$EnableCmdPalAOT,
|
||||
[switch]$Clean,
|
||||
[switch]$SkipBuild,
|
||||
[switch]$Help
|
||||
)
|
||||
|
||||
if ($Help) {
|
||||
Write-Host "Usage: .\build-installer.ps1 [-Platform <x64|arm64>] [-Configuration <Release|Debug>] [-PerUser <true|false>] [-Clean] [-SkipBuild]"
|
||||
Write-Host "Usage: .\build-installer.ps1 [-Platform <x64|arm64>] [-Configuration <Release|Debug>] [-PerUser <true|false>] [-Version <0.0.1>] [-EnableCmdPalAOT] [-Clean] [-SkipBuild]"
|
||||
Write-Host " -Platform Target platform (default: auto-detect or x64)"
|
||||
Write-Host " -Configuration Build configuration (default: Release)"
|
||||
Write-Host " -PerUser Build per-user installer (default: true)"
|
||||
Write-Host " -Version Overwrites the PowerToys version (default: from src\Version.props)"
|
||||
Write-Host " -EnableCmdPalAOT Enable AOT compilation for CmdPal (slower build)"
|
||||
Write-Host " -Clean Clean output directories before building"
|
||||
Write-Host " -SkipBuild Skip building the main solution and tools (assumes they are already built)"
|
||||
Write-Host " -Help Show this help message"
|
||||
@@ -96,13 +100,11 @@ if (-not $repoRoot -or -not (Test-Path (Join-Path $repoRoot "PowerToys.slnx")))
|
||||
}
|
||||
|
||||
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"
|
||||
$buildOutputPath = Join-Path $repoRoot "$Platform\$Configuration"
|
||||
|
||||
# Clean should be done first before any other steps
|
||||
if ($Clean) {
|
||||
if (Test-Path $cmdpalOutputPath) {
|
||||
Write-Host "[CLEAN] Removing previous output: $cmdpalOutputPath"
|
||||
@@ -127,7 +129,107 @@ if ($Clean) {
|
||||
RunMSBuild 'PowerToys.slnx' '/t:Clean' $Platform $Configuration
|
||||
}
|
||||
|
||||
# Set up versioning using versionSetting.ps1 if Version is provided
|
||||
# These files will be modified by versionSetting.ps1 and need to be restored after build
|
||||
$versionFilesToRestore = @(
|
||||
"src\Version.props",
|
||||
"src\CmdPalVersion.props",
|
||||
"src\modules\powerrename\PowerRenameContextMenu\AppxManifest.xml",
|
||||
"src\modules\imageresizer\ImageResizerContextMenu\AppxManifest.xml",
|
||||
"src\modules\FileLocksmith\FileLocksmithContextMenu\AppxManifest.xml",
|
||||
"src\modules\NewPlus\NewShellExtensionContextMenu\AppxManifest.xml"
|
||||
)
|
||||
$versionFileBackups = @{}
|
||||
|
||||
# These files are generated by Terminal versioning and need to be cleaned up after build
|
||||
$cmdpalGeneratedFiles = @(
|
||||
"src\modules\cmdpal\Directory.Build.props",
|
||||
"src\modules\cmdpal\Directory.Build.targets",
|
||||
"src\modules\cmdpal\Microsoft.CmdPal.UI\BuildInfo.xml",
|
||||
"src\modules\cmdpal\Microsoft.CmdPal.UI\GeneratedPackage.appxmanifest",
|
||||
"src\modules\cmdpal\ext\ProcessMonitorExtension\BuildInfo.xml",
|
||||
"src\modules\cmdpal\ext\ProcessMonitorExtension\GeneratedPackage.appxmanifest",
|
||||
"src\modules\cmdpal\ext\SamplePagesExtension\BuildInfo.xml",
|
||||
"src\modules\cmdpal\ext\SamplePagesExtension\GeneratedPackage.appxmanifest"
|
||||
)
|
||||
|
||||
# Backup all version files before any versioning scripts run
|
||||
Write-Host "[VERSION] Backing up version files before modification..."
|
||||
foreach ($relPath in $versionFilesToRestore) {
|
||||
$fullPath = Join-Path $repoRoot $relPath
|
||||
if (Test-Path $fullPath) {
|
||||
$versionFileBackups[$relPath] = Get-Content $fullPath -Raw
|
||||
Write-Host " Backed up: $relPath"
|
||||
}
|
||||
}
|
||||
|
||||
if ($Version) {
|
||||
Write-Host "[VERSION] Setting PowerToys version to $Version using versionSetting.ps1..."
|
||||
$versionScript = Join-Path $repoRoot ".pipelines\versionSetting.ps1"
|
||||
if (Test-Path $versionScript) {
|
||||
& $versionScript -versionNumber $Version -DevEnvironment 'Local'
|
||||
if (-not $?) {
|
||||
Write-Error "versionSetting.ps1 failed"
|
||||
exit 1
|
||||
}
|
||||
} else {
|
||||
Write-Error "Could not find versionSetting.ps1 at: $versionScript"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host "[VERSION] Setting up versioning using Microsoft.Windows.Terminal.Versioning..."
|
||||
|
||||
# Check for nuget.exe - download to AppData if not available
|
||||
$nugetDownloaded = $false
|
||||
$nugetPath = $null
|
||||
if (-not (Get-Command nuget -ErrorAction SilentlyContinue)) {
|
||||
Write-Warning "nuget.exe not found in PATH. Attempting to download..."
|
||||
$nugetUrl = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"
|
||||
$nugetDir = Join-Path $env:LOCALAPPDATA "PowerToys\BuildTools"
|
||||
if (-not (Test-Path $nugetDir)) { New-Item -ItemType Directory -Path $nugetDir -Force | Out-Null }
|
||||
$nugetPath = Join-Path $nugetDir "nuget.exe"
|
||||
if (-not (Test-Path $nugetPath)) {
|
||||
try {
|
||||
Invoke-WebRequest $nugetUrl -OutFile $nugetPath
|
||||
$nugetDownloaded = $true
|
||||
} catch {
|
||||
Write-Error "Failed to download nuget.exe. Please install it manually and add to PATH."
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
$env:Path += ";$nugetDir"
|
||||
}
|
||||
|
||||
# Install Terminal versioning package to AppData
|
||||
$versioningDir = Join-Path $env:LOCALAPPDATA "PowerToys\BuildTools\.versioning"
|
||||
if (-not (Test-Path $versioningDir)) { New-Item -ItemType Directory -Path $versioningDir -Force | Out-Null }
|
||||
|
||||
$configFile = Join-Path $repoRoot ".pipelines\release-nuget.config"
|
||||
|
||||
# Install the package
|
||||
# Use -ExcludeVersion to make the path predictable
|
||||
nuget install Microsoft.Windows.Terminal.Versioning -ConfigFile $configFile -OutputDirectory $versioningDir -ExcludeVersion -NonInteractive
|
||||
|
||||
$versionRoot = Join-Path $versioningDir "Microsoft.Windows.Terminal.Versioning"
|
||||
$setupScript = Join-Path $versionRoot "build\Setup.ps1"
|
||||
|
||||
if (Test-Path $setupScript) {
|
||||
& $setupScript -ProjectDirectory (Join-Path $repoRoot "src\modules\cmdpal") -Verbose
|
||||
} else {
|
||||
Write-Error "Could not find Setup.ps1 in $versionRoot"
|
||||
}
|
||||
|
||||
# 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 ''
|
||||
|
||||
$commonArgs = '/p:CIBuild=true /p:IsPipeline=true'
|
||||
|
||||
if ($EnableCmdPalAOT) {
|
||||
$commonArgs += " /p:EnableCmdPalAOT=true"
|
||||
}
|
||||
|
||||
# No local projects found (or continuing) - build full solution and tools
|
||||
if (-not $SkipBuild) {
|
||||
RestoreThenBuild 'PowerToys.slnx' $commonArgs $Platform $Configuration
|
||||
@@ -191,4 +293,24 @@ if (Test-Path $msiEnUsDir) {
|
||||
|
||||
RunMSBuild 'installer\PowerToysSetup.slnx' "$commonArgs /m /t:PowerToysBootstrapperVNext /p:PerUser=$PerUser" $Platform $Configuration
|
||||
|
||||
# Restore version files if they were backed up
|
||||
if ($versionFileBackups.Count -gt 0) {
|
||||
Write-Host "[VERSION] Restoring version files to original state..."
|
||||
foreach ($relPath in $versionFileBackups.Keys) {
|
||||
$fullPath = Join-Path $repoRoot $relPath
|
||||
Set-Content -Path $fullPath -Value $versionFileBackups[$relPath] -NoNewline
|
||||
Write-Host " Restored: $relPath"
|
||||
}
|
||||
}
|
||||
|
||||
# Clean up cmdpal generated files from Terminal versioning
|
||||
Write-Host "[CLEANUP] Removing cmdpal generated files..."
|
||||
foreach ($relPath in $cmdpalGeneratedFiles) {
|
||||
$fullPath = Join-Path $repoRoot $relPath
|
||||
if (Test-Path $fullPath) {
|
||||
Remove-Item $fullPath -Force
|
||||
Write-Host " Removed: $relPath"
|
||||
}
|
||||
}
|
||||
|
||||
Write-Host '[PIPELINE] Completed'
|
||||
|
||||
Reference in New Issue
Block a user