Add function to create a new nuget.config file (#8170)
Add a function to create a NuGet.config file to consume packages from the specified feed URL using the specified credentials. - Also, exclude the `nuget.config` file under `src/Modules` from being clean by `Start-PSBuild -clean`
This commit is contained in:
parent
b5ab2ddd40
commit
e1d8765f9e
35
build.psm1
35
build.psm1
|
@ -271,7 +271,8 @@ function Start-PSBuild {
|
|||
Push-Location $PSScriptRoot
|
||||
try {
|
||||
# Excluded sqlite3 folder is due to this Roslyn issue: https://github.com/dotnet/roslyn/issues/23060
|
||||
git clean -fdx --exclude .vs/PowerShell/v15/Server/sqlite3
|
||||
# Excluded src/Modules/nuget.config as this is required for release build.
|
||||
git clean -fdx --exclude .vs/PowerShell/v15/Server/sqlite3 --exclude src/Modules/nuget.config
|
||||
} finally {
|
||||
Pop-Location
|
||||
}
|
||||
|
@ -3043,3 +3044,35 @@ function New-TestPackage
|
|||
|
||||
[System.IO.Compression.ZipFile]::CreateFromDirectory($packageRoot, $packagePath)
|
||||
}
|
||||
|
||||
function New-NugetConfigFile
|
||||
{
|
||||
param(
|
||||
[Parameter(Mandatory=$true)] [string] $NugetFeedUrl,
|
||||
[Parameter(Mandatory=$true)] [string] $FeedName,
|
||||
[Parameter(Mandatory=$true)] [string] $UserName,
|
||||
[Parameter(Mandatory=$true)] [string] $ClearTextPAT,
|
||||
[Parameter(Mandatory=$true)] [string] $Destination
|
||||
)
|
||||
|
||||
$nugetConfigTemplate = @'
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<clear />
|
||||
<add key="[FEEDNAME]" value="[FEED]" />
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
|
||||
</packageSources>
|
||||
<packageSourceCredentials>
|
||||
<[FEEDNAME]>
|
||||
<add key="Username" value="[USERNAME]" />
|
||||
<add key="ClearTextPassword" value="[PASSWORD]" />
|
||||
</[FEEDNAME]>
|
||||
</packageSourceCredentials>
|
||||
</configuration>
|
||||
'@
|
||||
|
||||
$content = $nugetConfigTemplate.Replace('[FEED]', $NugetFeedUrl).Replace('[FEEDNAME]', $FeedName).Replace('[USERNAME]', $UserName).Replace('[PASSWORD]', $ClearTextPAT)
|
||||
|
||||
Set-Content -Path (Join-Path $Destination 'nuget.config') -Value $content -Force
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue