From 91b7a99e7691d03792b463687209049d88d684e2 Mon Sep 17 00:00:00 2001 From: Shawn Yuan <128874481+shuaiyuanxx@users.noreply.github.com> Date: Thu, 18 Dec 2025 11:39:35 +0800 Subject: [PATCH] Update BuildWithLatestWinAppSdkDaily pipeline to use 1.8 wasdk (#44183) ## Summary of the Pull Request This pull request refactors the WindowsAppSDK update and NuGet restore pipeline to improve dependency resolution and configuration management, especially for version 1.8 and above. The changes streamline how package versions are detected and updated across multiple project files, introduce more robust handling of NuGet sources and mappings, and modernize the restore step to use the `dotnet` CLI for better compatibility. ## PR Checklist - [ ] Closes: #xxx - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx ## Detailed Description of the Pull Request / Additional comments ## Validation Steps Performed --------- Signed-off-by: Shawn Yuan (from Dev Box) --- .pipelines/UpdateVersions.ps1 | 219 ++++++++++++------ .../v2/ci-using-the-latest-winappsdk.yml | 4 +- ...eps-update-winappsdk-and-restore-nuget.yml | 51 +--- 3 files changed, 163 insertions(+), 111 deletions(-) diff --git a/.pipelines/UpdateVersions.ps1 b/.pipelines/UpdateVersions.ps1 index 0be3e3d30b..1c66db5459 100644 --- a/.pipelines/UpdateVersions.ps1 +++ b/.pipelines/UpdateVersions.ps1 @@ -16,32 +16,7 @@ Param( [string]$sourceLink = "https://microsoft.pkgs.visualstudio.com/ProjectReunion/_packaging/Project.Reunion.nuget.internal/nuget/v3/index.json" ) -function Update-NugetConfig { - param ( - [string]$filePath = [System.IO.Path]::Combine($rootPath, "nuget.config") - ) - Write-Host "Updating nuget.config file" - [xml]$xml = Get-Content -Path $filePath - - # Add localpackages source into nuget.config - $packageSourcesNode = $xml.configuration.packageSources - $addNode = $xml.CreateElement("add") - $addNode.SetAttribute("key", "localpackages") - $addNode.SetAttribute("value", "localpackages") - $packageSourcesNode.AppendChild($addNode) | Out-Null - - # Remove tag and its content - $packageSourceMappingNode = $xml.configuration.packageSourceMapping - if ($packageSourceMappingNode) { - $xml.configuration.RemoveChild($packageSourceMappingNode) | Out-Null - } - - # print nuget.config after modification - $xml.OuterXml - # Save the modified nuget.config file - $xml.Save($filePath) -} function Read-FileWithEncoding { param ( @@ -71,6 +46,132 @@ function Write-FileWithEncoding { $writer.Close() } + +function Add-NuGetSourceAndMapping { + param ( + [xml]$Xml, + [string]$Key, + [string]$Value, + [string[]]$Patterns + ) + + # Ensure packageSources exists + if (-not $Xml.configuration.packageSources) { + $Xml.configuration.AppendChild($Xml.CreateElement("packageSources")) | Out-Null + } + $sources = $Xml.configuration.packageSources + + # Add/Update Source + $sourceNode = $sources.SelectSingleNode("add[@key='$Key']") + if (-not $sourceNode) { + $sourceNode = $Xml.CreateElement("add") + $sourceNode.SetAttribute("key", $Key) + $sources.AppendChild($sourceNode) | Out-Null + } + $sourceNode.SetAttribute("value", $Value) + + # Ensure packageSourceMapping exists + if (-not $Xml.configuration.packageSourceMapping) { + $Xml.configuration.AppendChild($Xml.CreateElement("packageSourceMapping")) | Out-Null + } + $mapping = $Xml.configuration.packageSourceMapping + + # Remove invalid packageSource nodes (missing key or empty key) + $invalidNodes = $mapping.SelectNodes("packageSource[not(@key) or @key='']") + if ($invalidNodes) { + foreach ($node in $invalidNodes) { + $mapping.RemoveChild($node) | Out-Null + } + } + + # Add/Update Mapping Source + $mappingSource = $mapping.SelectSingleNode("packageSource[@key='$Key']") + if (-not $mappingSource) { + $mappingSource = $Xml.CreateElement("packageSource") + $mappingSource.SetAttribute("key", $Key) + # Insert at top for priority + if ($mapping.HasChildNodes) { + $mapping.InsertBefore($mappingSource, $mapping.FirstChild) | Out-Null + } else { + $mapping.AppendChild($mappingSource) | Out-Null + } + } + + # Double check and force attribute + if (-not $mappingSource.HasAttribute("key")) { + $mappingSource.SetAttribute("key", $Key) + } + + # Update Patterns + # RemoveAll() removes all child nodes AND attributes, so we must re-set the key afterwards + $mappingSource.RemoveAll() + $mappingSource.SetAttribute("key", $Key) + + foreach ($pattern in $Patterns) { + $pkg = $Xml.CreateElement("package") + $pkg.SetAttribute("pattern", $pattern) + $mappingSource.AppendChild($pkg) | Out-Null + } +} + +function Resolve-WinAppSdkSplitDependencies { + Write-Host "Version $WinAppSDKVersion detected. Resolving split dependencies..." + $installDir = Join-Path $rootPath "localpackages\output" + New-Item -ItemType Directory -Path $installDir -Force | Out-Null + + # Create a temporary nuget.config to avoid interference from the repo's config + $tempConfig = Join-Path $env:TEMP "nuget_$(Get-Random).config" + Set-Content -Path $tempConfig -Value "" + + try { + # Extract BuildTools version from Directory.Packages.props to ensure we have the required version + $dirPackagesProps = Join-Path $rootPath "Directory.Packages.props" + if (Test-Path $dirPackagesProps) { + $propsContent = Get-Content $dirPackagesProps -Raw + if ($propsContent -match '' - $oldVersionString = '' - $content = $content -replace $oldVersionString, $newVersionString + $isModified = $false + + foreach ($pkgId in $packageVersions.Keys) { + $ver = $packageVersions[$pkgId] + # Escape dots in package ID for regex + $pkgIdRegex = $pkgId -replace '\.', '\.' + + $newVersionString = "" + $oldVersionString = "" + + if ($content -match " - install "Microsoft.WindowsAppSDK" - -Source "$(Build.SourcesDirectory)\localpackages\NugetPackages" - -Version "$(WinAppSDKVersion)" - -OutputDirectory "$(Build.SourcesDirectory)\localpackages\output" - -FallbackSource "https://microsoft.pkgs.visualstudio.com/ProjectReunion/_packaging/Project.Reunion.nuget.internal/nuget/v3/index.json" - -- task: NuGetCommand@2 - displayName: 'Restore NuGet packages' +- task: DotNetCoreCLI@2 + displayName: 'Restore NuGet packages (dotnet)' inputs: command: 'restore' + projects: '$(build.sourcesdirectory)\**\*.slnx' feedsToUse: 'config' nugetConfigPath: '$(build.sourcesdirectory)\nuget.config' - restoreSolution: '$(build.sourcesdirectory)\**\*.sln' - includeNuGetOrg: false - -- task: NuGetCommand@2 - displayName: 'Restore NuGet packages (slnx)' - inputs: - command: 'restore' - feedsToUse: 'config' - nugetConfigPath: '$(build.sourcesdirectory)\nuget.config' - restoreSolution: '$(build.sourcesdirectory)\**\*.slnx' - includeNuGetOrg: false