@@ -955,4 +955,34 @@ Function Remove-EditorconfigFile() {
955955 # See https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/configuration-files#severity-options
956956 Remove-Item $editorconfigFilePath
957957 Trace-Log " Removed $editorconfigFilePath "
958+ }
959+
960+ Function Add-PackageSourceMapping (
961+ [Parameter (Mandatory = $True )][string ]$NuGetConfigPath ,
962+ [Parameter (Mandatory = $True )][string ]$SourceKey ,
963+ [Parameter (Mandatory = $True )][string []]$Patterns ) {
964+ if (-not [System.IO.Path ]::IsPathRooted($NuGetConfigPath )) {
965+ $NuGetConfigPath = Join-Path $PWD $NuGetConfigPath
966+ }
967+
968+ $config = [xml ](Get-Content - Raw $NuGetConfigPath )
969+ if (-not $config.configuration.packageSourceMapping ) {
970+ Write-Host " No package source mapping section. Not doing anything."
971+ return
972+ }
973+
974+ $packageSourceNode = $config.configuration.packageSourceMapping.packageSource | Where-Object { $_.key -eq $SourceKey }
975+ if (-not $packageSourceNode ) {
976+ $packageSourceNode = $config.CreateElement (" packageSource" )
977+ $packageSourceNode.SetAttribute (" key" , $SourceKey )
978+ $config.configuration.packageSourceMapping.AppendChild ($packageSourceNode ) | Out-Null
979+ }
980+
981+ foreach ($pattern in $Patterns )
982+ {
983+ $package = $config.CreateElement (" package" )
984+ $package.SetAttribute (" pattern" , $pattern )
985+ $packageSourceNode.AppendChild ($package ) | Out-Null
986+ }
987+ $config.Save ($NuGetConfigPath )
958988}
0 commit comments