restore state after install

This commit is contained in:
Kai Tao (from Dev Box)
2025-12-09 20:47:09 +08:00
parent 44e38d6dae
commit a2b337505d

View File

@@ -141,15 +141,29 @@ $versionFilesToRestore = @(
)
$versionFileBackups = @{}
if ($Version) {
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
}
}
# 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) {
@@ -166,25 +180,30 @@ if ($Version) {
Write-Host "[VERSION] Setting up versioning using Microsoft.Windows.Terminal.Versioning..."
# Check for nuget.exe
# 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"
$nugetPath = Join-Path $repoRoot "nuget.exe"
try {
Invoke-WebRequest $nugetUrl -OutFile $nugetPath
$env:Path += ";$repoRoot"
$nugetDownloaded = $true
} catch {
Write-Error "Failed to download nuget.exe. Please install it manually and add to PATH."
exit 1
$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"
}
$versioningDir = Join-Path $repoRoot ".versioning"
if (-not (Test-Path $versioningDir)) { New-Item -ItemType Directory -Path $versioningDir | Out-Null }
# 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"
@@ -284,10 +303,14 @@ if ($versionFileBackups.Count -gt 0) {
}
}
# Clean up downloaded nuget.exe if we downloaded it
if ($nugetDownloaded -and $nugetPath -and (Test-Path $nugetPath)) {
Write-Host "[CLEANUP] Removing downloaded nuget.exe..."
Remove-Item $nugetPath -Force
# 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'