This commit is contained in:
Shawn Yuan (from Dev Box)
2025-12-08 15:10:38 +08:00
parent 9b39e11e61
commit ee4e455a97
2 changed files with 44 additions and 35 deletions

View File

@@ -117,20 +117,21 @@ $packageVersions = @{ "Microsoft.WindowsAppSDK" = $WinAppSDKVersion }
if ($WinAppSDKVersion -match "^1\.8") {
Write-Host "Version $WinAppSDKVersion detected. Resolving split dependencies..."
$tempDir = Join-Path $env:TEMP "winappsdk_deps_$(Get-Random)"
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
try {
$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 $tempDir "nuget.config"
$tempConfig = Join-Path $env:TEMP "nuget_$(Get-Random).config"
Set-Content -Path $tempConfig -Value "<?xml version='1.0' encoding='utf-8'?><configuration><packageSources><clear /><add key='TempSource' value='$sourceLink' /></packageSources></configuration>"
# Download package to inspect nuspec
$nugetArgs = "install Microsoft.WindowsAppSDK -Version $WinAppSDKVersion -ConfigFile $tempConfig -OutputDirectory $tempDir -NonInteractive -NoCache"
try {
# Download package to inspect nuspec and keep it for the build
$nugetArgs = "install Microsoft.WindowsAppSDK -Version $WinAppSDKVersion -ConfigFile $tempConfig -OutputDirectory $installDir -NonInteractive -NoCache"
Invoke-Expression "nuget $nugetArgs" | Out-Null
# Parse dependencies from the installed folders
# Folder structure is typically {PackageId}.{Version}
$directories = Get-ChildItem -Path $tempDir -Directory
$directories = Get-ChildItem -Path $installDir -Directory
foreach ($dir in $directories) {
if ($dir.Name -match "^(Microsoft\.WindowsAppSDK.*?)\.(\d.*)$") {
$pkgId = $Matches[1]
@@ -142,7 +143,7 @@ if ($WinAppSDKVersion -match "^1\.8") {
} catch {
Write-Warning "Failed to resolve dependencies: $_"
} finally {
Remove-Item $tempDir -Recurse -Force -ErrorAction SilentlyContinue
Remove-Item $tempConfig -Force -ErrorAction SilentlyContinue
}
}

View File

@@ -7,6 +7,39 @@ parameters:
default: false
steps:
- task: PowerShell@2
displayName: 'Configure NuGet'
inputs:
targetType: 'inline'
script: |
$nugetConfigPath = "$(Build.SourcesDirectory)\nuget.config"
$localPackagesPath = "$(Build.SourcesDirectory)\localpackages\output"
# Ensure the directory exists so it's a valid source
New-Item -ItemType Directory -Path $localPackagesPath -Force | Out-Null
Write-Host "Modifying $nugetConfigPath..."
[xml]$xml = Get-Content -Path $nugetConfigPath
# Add localpackages source
$packageSourcesNode = $xml.configuration.packageSources
if (-not $packageSourcesNode.SelectSingleNode("add[@key='localpackages']")) {
$addNode = $xml.CreateElement("add")
$addNode.SetAttribute("key", "localpackages")
$addNode.SetAttribute("value", $localPackagesPath)
$packageSourcesNode.AppendChild($addNode) | Out-Null
}
# Remove packageSourceMapping to ensure we can restore from both sources without restriction
$packageSourceMappingNode = $xml.configuration.packageSourceMapping
if ($packageSourceMappingNode) {
$xml.configuration.RemoveChild($packageSourceMappingNode) | Out-Null
Write-Host "Removed packageSourceMapping."
}
$xml.Save($nugetConfigPath)
Get-Content $nugetConfigPath
- task: NuGetAuthenticate@1
displayName: 'NuGet Authenticate'
@@ -22,31 +55,6 @@ steps:
- script: echo $(WinAppSDKVersion)
displayName: 'Display WinAppSDK Version Found'
- task: DownloadPipelineArtifact@2
displayName: 'Download WindowsAppSDK'
inputs:
buildType: 'specific'
project: '55e8140e-57ac-4e5f-8f9c-c7c15b51929d'
definition: '104083'
buildVersionToDownload: 'latestFromBranch'
branchName: 'refs/heads/release/${{ parameters.versionNumber }}-stable'
artifactName: 'WindowsAppSDK_Nuget_And_MSIX'
targetPath: '$(Build.SourcesDirectory)\localpackages'
- script: dir $(Build.SourcesDirectory)\localpackages\NugetPackages
displayName: 'List downloaded packages'
- task: NuGetCommand@2
displayName: 'Install WindowsAppSDK'
inputs:
command: 'custom'
arguments: >
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'
inputs: