update pwsh

This commit is contained in:
Shawn Yuan (from Dev Box)
2025-12-18 08:57:15 +08:00
parent 699b8e2af8
commit fc46fd3de6

View File

@@ -247,76 +247,3 @@ Get-ChildItem -Path $rootPath -Recurse "Directory.Packages.props" | ForEach-Obje
Write-Host "Modified " $_.FullName
}
}
# Update packages.config files
Get-ChildItem -Path $rootPath -Recurse "packages.config" | ForEach-Object {
$file = Read-FileWithEncoding -Path $_.FullName
$content = $file.Content
$isModified = $false
foreach ($pkgId in $packageVersions.Keys) {
$ver = $packageVersions[$pkgId]
# Escape dots in package ID for regex
$pkgIdRegex = $pkgId -replace '\.', '\.'
# packages.config format: <package id="PackageId" version="Version" ... />
$newPackageString = "<package id=""$pkgId"" version=""$ver"""
$oldPackagePattern = "<package id=""$pkgIdRegex"" version=""[^""]+"""
if ($content -match "<package id=""$pkgIdRegex""") {
# Update existing package
if ($content -notmatch [regex]::Escape($newPackageString)) {
$content = $content -replace $oldPackagePattern, $newPackageString
$isModified = $true
}
}
}
if ($isModified) {
Write-FileWithEncoding -Path $_.FullName -Content $content -Encoding $file.encoding
Write-Host "Modified " $_.FullName
}
}
# Update .vcxproj files with hardcoded package paths
Get-ChildItem -Path $rootPath -Recurse "*.vcxproj" | ForEach-Object {
$file = Read-FileWithEncoding -Path $_.FullName
$content = $file.Content
$isModified = $false
foreach ($pkgId in $packageVersions.Keys) {
$ver = $packageVersions[$pkgId]
# Escape dots in package ID for regex
$pkgIdRegex = $pkgId -replace '\.', '\.'
# Look for properties like <WasdkNuget>...packages\Microsoft.WindowsAppSDK.1.2.3...</WasdkNuget>
# Regex to match: >...packages\PackageId.OldVersion<
# We want to replace OldVersion with NewVersion
# Pattern: matches "packages\PackageId.Version" inside a tag value
# We use a lookbehind for "packages\" and PackageId, then match the version
$pattern = "(?<=packages\\$pkgIdRegex\.)([\d\.]+[-a-zA-Z0-9]*)(?=<)"
if ($content -match $pattern) {
$currentVersionInFile = $Matches[0]
if ($currentVersionInFile -ne $ver) {
# Replace all occurrences of this specific package version path
# We construct a specific regex for replacement to be safe
$specificPattern = "packages\\$pkgIdRegex\.$([regex]::Escape($currentVersionInFile))"
$replacement = "packages\$pkgId.$ver"
$content = $content -replace $specificPattern, $replacement
$isModified = $true
Write-Host "Updating $pkgId in $($_.Name): $currentVersionInFile -> $ver"
}
}
}
if ($isModified) {
Write-FileWithEncoding -Path $_.FullName -Content $content -Encoding $file.encoding
Write-Host "Modified " $_.FullName
}
}