-
Notifications
You must be signed in to change notification settings - Fork 333
Expand file tree
/
Copy pathUpdateVersions.ps1
More file actions
111 lines (101 loc) · 4.85 KB
/
Copy pathUpdateVersions.ps1
File metadata and controls
111 lines (101 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<#
.SYNOPSIS
Updates WinAppSDK-related package references across the samples to a specified version.
.DESCRIPTION
Ensures the requested Microsoft.WindowsAppSDK NuGet package (and key dependencies) is available locally,
then rewrites packages.config, project files, and Directory.Packages.props entries so they all target the
provided version. This script is intended to be the single place to bump WinAppSDK versions in the repo.
.PARAMETER WinAppSDKVersion
Version of Microsoft.WindowsAppSDK to apply (for example, 1.8.251106002). You can discover the latest
stable, servicing, or preview versions at https://www.nuget.org/packages/Microsoft.WindowsAppSDK/.
.PARAMETER NuGetPackagesFolder
Optional path to a NuGet packages directory that already contains the desired packages. When omitted the
script restores the packages into the local ./packages folder.
.EXAMPLE
.\UpdateVersions.ps1 -WinAppSDKVersion 1.8.251106002
Updates all projects to reference Microsoft.WindowsAppSDK version 1.8.251106002, restoring packages into
the default ./packages directory when needed.
#>
Param(
[string]$WinAppSDKVersion = "",
[string]$NuGetPackagesFolder = ""
)
# Ensure a local packages cache exists when the caller does not provide one.
# A lightweight restore keeps this script self-contained for version updates.
if ($NuGetPackagesFolder -eq "") {
$NuGetPackagesFolder = Join-Path $PSScriptRoot "packages"
Write-Host "NuGetPackagesFolder not supplied. Using default: $NuGetPackagesFolder"
}
if (!(Test-Path $NuGetPackagesFolder)) {
New-Item -ItemType Directory -Path $NuGetPackagesFolder -Force | Out-Null
}
$nugetToolDir = Join-Path $PSScriptRoot ".nuget"
$nugetExe = Join-Path $nugetToolDir "nuget.exe"
if (!(Test-Path $nugetExe)) {
if (!(Test-Path $nugetToolDir)) { New-Item -ItemType Directory -Path $nugetToolDir | Out-Null }
Write-Host "Downloading nuget.exe..."
try {
Invoke-WebRequest https://dist.nuget.org/win-x86-commandline/latest/nuget.exe `
-OutFile $nugetExe `
-ErrorAction Stop
}
catch {
Write-Warning "Failed to download nuget.exe: $($_.Exception.Message)"
}
}
# Always install/refresh the requested Microsoft.WindowsAppSDK version (idempotent if already present).
if ([string]::IsNullOrWhiteSpace($WinAppSDKVersion)) {
$winAppSdkNugetUrl = "https://www.nuget.org/packages/Microsoft.WindowsAppSDK/"
Write-Warning "WinAppSDKVersion not supplied; cannot install Microsoft.WindowsAppSDK package automatically."
Write-Warning "Visit $winAppSdkNugetUrl to determine the latest version, then rerun the script."
exit 1
}
else {
if (!(Test-Path $NuGetPackagesFolder)) { New-Item -ItemType Directory -Path $NuGetPackagesFolder | Out-Null }
Write-Host "Installing Microsoft.WindowsAppSDK $WinAppSDKVersion into $NuGetPackagesFolder (running inside folder)"
Push-Location $NuGetPackagesFolder
try {
& $nugetExe install Microsoft.WindowsAppSDK `
-Version $WinAppSDKVersion `
-OutputDirectory . `
-Prerelease `
-DependencyVersion Highest
if ($LASTEXITCODE -ne 0) {
throw "nuget.exe failed with exit code $LASTEXITCODE"
}
}
catch {
Write-Warning $_
}
finally {
Pop-Location
}
}
# Seed the package/version map with the WinAppSDK metapackage.
$nugetPackageToVersionTable = @{"Microsoft.WindowsAppSDK" = $WinAppSDKVersion }
# When a populated packages folder is available, harvest dependency versions from it.
Get-ChildItem $NuGetPackagesFolder |
Sort-Object Name |
Where-Object { $_.Name -like "Microsoft.WindowsAppSDK.*" -or
$_.Name -like "Microsoft.Windows.SDK.BuildTools.*" -or
$_.Name -like "Microsoft.Web.WebView2.*" } |
Where-Object { $_.Name -notlike "*.nupkg" } |
ForEach-Object {
if ($_.Name -match "^(Microsoft\.WindowsAppSDK\.[a-zA-Z]+)\.([0-9].*)$" -or
$_.Name -match "^(Microsoft\.Windows\.SDK\.BuildTools\.MSIX)\.([0-9].*)$" -or
$_.Name -match "^(Microsoft\.Windows\.SDK\.BuildTools)\.([0-9].*)$" -or
$_.Name -match "^(Microsoft\.Web\.WebView2)\.([0-9].*)$") {
$nugetPackageToVersionTable[$Matches[1]] = $Matches[2]
Write-Host "Found $($Matches[1]) - $($Matches[2])"
}
}
Get-ChildItem -Recurse Directory.Packages.props -Path $PSScriptRoot | foreach-object {
$content = Get-Content $_.FullName -Raw
foreach ($nugetPackageToVersion in $nugetPackageToVersionTable.GetEnumerator()) {
$newVersionString = 'PackageVersion Include="' + $nugetPackageToVersion.Key + '" Version="' + $nugetPackageToVersion.Value + '"'
$oldVersionString = 'PackageVersion Include="' + $nugetPackageToVersion.Key + '" Version="[-.0-9a-zA-Z]*"'
$content = $content -replace $oldVersionString, $newVersionString
}
Set-Content -Path $_.FullName -Value $content
Write-Host "Modified " $_.FullName
}