diff --git a/.pipelines/UpdateVersions.ps1 b/.pipelines/UpdateVersions.ps1 index e2bbd65e2b..4231a866a1 100644 --- a/.pipelines/UpdateVersions.ps1 +++ b/.pipelines/UpdateVersions.ps1 @@ -278,5 +278,45 @@ Get-ChildItem -Path $rootPath -Recurse "packages.config" | ForEach-Object { } } +# 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 ...packages\Microsoft.WindowsAppSDK.1.2.3... + # 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 + } +} +