This commit is contained in:
Shawn Yuan (from Dev Box)
2025-12-09 10:57:09 +08:00
parent 0f0414d5cb
commit f645e5b3d8

View File

@@ -8,50 +8,32 @@ parameters:
steps: steps:
- task: PowerShell@2 - task: PowerShell@2
displayName: 'Configure NuGet' displayName: 'Generate Temporary NuGet Config'
inputs: inputs:
targetType: 'inline' targetType: 'inline'
script: | script: |
$nugetConfigPath = "$(Build.SourcesDirectory)\nuget.config" $nugetConfigPath = "$(Build.SourcesDirectory)\nuget.config"
$tempConfigPath = "$(Build.SourcesDirectory)\nuget_temp.config"
$localPackagesPath = "$(Build.SourcesDirectory)\localpackages\output" $localPackagesPath = "$(Build.SourcesDirectory)\localpackages\output"
# Ensure the directory exists so it's a valid source # Ensure the directory exists so it's a valid source
New-Item -ItemType Directory -Path $localPackagesPath -Force | Out-Null New-Item -ItemType Directory -Path $localPackagesPath -Force | Out-Null
Write-Host "Modifying $nugetConfigPath..." Write-Host "Creating $tempConfigPath from $nugetConfigPath using text replacement..."
[xml]$xml = Get-Content -Path $nugetConfigPath $content = Get-Content -Path $nugetConfigPath -Raw
# Add localpackages source # Add localpackages source
$packageSourcesNode = $xml.configuration.packageSources # We insert it before the closing packageSources tag
if (-not $packageSourcesNode.SelectSingleNode("add[@key='localpackages']")) { $sourceInsert = " <add key=""localpackages"" value=""$localPackagesPath"" />`r`n "
$addNode = $xml.CreateElement("add") $content = $content -replace "</packageSources>", "$sourceInsert</packageSources>"
$addNode.SetAttribute("key", "localpackages")
$addNode.SetAttribute("value", $localPackagesPath)
$packageSourcesNode.AppendChild($addNode) | Out-Null
}
# Update packageSourceMapping to include localpackages for WindowsAppSDK # Add mapping for WindowsAppSDK
$packageSourceMappingNode = $xml.configuration.packageSourceMapping # We insert it after the opening packageSourceMapping tag to ensure it's first (highest priority)
if ($packageSourceMappingNode) { $mappingInsert = "`r`n <packageSource key=""localpackages"">`r`n <package pattern=""Microsoft.WindowsAppSDK*"" />`r`n </packageSource>"
# Create new packageSource element for localpackages $content = $content -replace "<packageSourceMapping>", "<packageSourceMapping>$mappingInsert"
$sourceNode = $xml.CreateElement("packageSource")
$sourceNode.SetAttribute("key", "localpackages")
$packageNode = $xml.CreateElement("package") Set-Content -Path $tempConfigPath -Value $content -Encoding UTF8
$packageNode.SetAttribute("pattern", "Microsoft.WindowsAppSDK*") Get-Content $tempConfigPath
$sourceNode.AppendChild($packageNode) | Out-Null
# Insert at the beginning to prioritize
if ($packageSourceMappingNode.HasChildNodes) {
$packageSourceMappingNode.InsertBefore($sourceNode, $packageSourceMappingNode.FirstChild) | Out-Null
} else {
$packageSourceMappingNode.AppendChild($sourceNode) | Out-Null
}
Write-Host "Updated packageSourceMapping."
}
$xml.Save($nugetConfigPath)
Get-Content $nugetConfigPath
- task: NuGetAuthenticate@1 - task: NuGetAuthenticate@1
displayName: 'NuGet Authenticate' displayName: 'NuGet Authenticate'
@@ -73,7 +55,7 @@ steps:
inputs: inputs:
command: 'restore' command: 'restore'
feedsToUse: 'config' feedsToUse: 'config'
nugetConfigPath: '$(build.sourcesdirectory)\nuget.config' nugetConfigPath: '$(build.sourcesdirectory)\nuget_temp.config'
restoreSolution: '$(build.sourcesdirectory)\**\*.sln' restoreSolution: '$(build.sourcesdirectory)\**\*.sln'
includeNuGetOrg: false includeNuGetOrg: false
@@ -82,6 +64,6 @@ steps:
inputs: inputs:
command: 'restore' command: 'restore'
feedsToUse: 'config' feedsToUse: 'config'
nugetConfigPath: '$(build.sourcesdirectory)\nuget.config' nugetConfigPath: '$(build.sourcesdirectory)\nuget_temp.config'
restoreSolution: '$(build.sourcesdirectory)\**\*.slnx' restoreSolution: '$(build.sourcesdirectory)\**\*.slnx'
includeNuGetOrg: false includeNuGetOrg: false