Skip to content

Commit c20433a

Browse files
Update infrastructure to consume private builds from .NET (#13427)
1 parent 112f1b9 commit c20433a

File tree

2 files changed

+96
-25
lines changed

2 files changed

+96
-25
lines changed

build.psm1

Lines changed: 51 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,8 @@ function Start-PSBuild {
303303
[ValidatePattern("^v\d+\.\d+\.\d+(-\w+(\.\d+)?)?$")]
304304
[ValidateNotNullOrEmpty()]
305305
[string]$ReleaseTag,
306-
[switch]$Detailed
306+
[switch]$Detailed,
307+
[switch]$InteractiveAuth
307308
)
308309

309310
if ($PSCmdlet.ParameterSetName -eq "Default" -and !$NoPSModuleRestore)
@@ -426,7 +427,7 @@ Fix steps:
426427
}
427428

428429
# handle Restore
429-
Restore-PSPackage -Options $Options -Force:$Restore
430+
Restore-PSPackage -Options $Options -Force:$Restore -InteractiveAuth:$InteractiveAuth
430431

431432
# handle ResGen
432433
# Heuristic to run ResGen on the fresh machine
@@ -618,7 +619,9 @@ function Restore-PSPackage
618619
[Parameter()]
619620
$Options = (Get-PSOptions -DefaultToNew),
620621

621-
[switch] $Force
622+
[switch] $Force,
623+
624+
[switch] $InteractiveAuth
622625
)
623626

624627
if (-not $ProjectDirs)
@@ -654,6 +657,10 @@ function Restore-PSPackage
654657
$RestoreArguments += "quiet"
655658
}
656659

660+
if ($InteractiveAuth) {
661+
$RestoreArguments += "--interactive"
662+
}
663+
657664
$ProjectDirs | ForEach-Object {
658665
$project = $_
659666
Write-Log -message "Run dotnet restore $project $RestoreArguments"
@@ -1639,7 +1646,9 @@ function Install-Dotnet {
16391646
[string]$Channel = $dotnetCLIChannel,
16401647
[string]$Version = $dotnetCLIRequiredVersion,
16411648
[switch]$NoSudo,
1642-
[string]$InstallDir
1649+
[string]$InstallDir,
1650+
[string]$AzureFeed,
1651+
[string]$FeedCredential
16431652
)
16441653

16451654
# This allows sudo install to be optional; needed when running in containers / as root
@@ -1674,33 +1683,57 @@ function Install-Dotnet {
16741683
Start-NativeExecution {
16751684
& $curl -sO $installObtainUrl/$installScript
16761685

1677-
if (-not $InstallDir) {
1678-
bash ./$installScript -c $Channel -v $Version
1679-
} else {
1680-
bash ./$installScript -c $Channel -v $Version -i $InstallDir
1686+
$bashArgs = @("./$installScript", '-c', $Channel, '-v', $Version)
1687+
1688+
if ($InstallDir) {
1689+
$bashArgs += @('-i', $InstallDir)
1690+
}
1691+
1692+
if ($AzureFeed) {
1693+
$bashArgs += @('-AzureFeed', $AzureFeed, '-FeedCredential', $FeedCredential)
16811694
}
1695+
1696+
bash @bashArgs
16821697
}
16831698
} elseif ($environment.IsWindows) {
16841699
Remove-Item -ErrorAction SilentlyContinue -Recurse -Force ~\AppData\Local\Microsoft\dotnet
16851700
$installScript = "dotnet-install.ps1"
16861701
Invoke-WebRequest -Uri $installObtainUrl/$installScript -OutFile $installScript
1687-
16881702
if (-not $environment.IsCoreCLR) {
1689-
if (-not $InstallDir) {
1690-
& ./$installScript -Channel $Channel -Version $Version
1691-
} else {
1692-
& ./$installScript -Channel $Channel -Version $Version -InstallDir $InstallDir
1703+
$installArgs = @{
1704+
Channel = $Channel
1705+
Version = $Version
16931706
}
1694-
} else {
1707+
1708+
if ($InstallDir) {
1709+
$installArgs += @{ InstallDir = $InstallDir }
1710+
}
1711+
1712+
if ($AzureFeed) {
1713+
$installArgs += @{
1714+
AzureFeed = $AzureFeed
1715+
$FeedCredential = $FeedCredential
1716+
}
1717+
}
1718+
1719+
& ./$installScript @installArgs
1720+
}
1721+
else {
16951722
# dotnet-install.ps1 uses APIs that are not supported in .NET Core, so we run it with Windows PowerShell
16961723
$fullPSPath = Join-Path -Path $env:windir -ChildPath "System32\WindowsPowerShell\v1.0\powershell.exe"
16971724
$fullDotnetInstallPath = Join-Path -Path $PWD.Path -ChildPath $installScript
16981725
Start-NativeExecution {
1699-
if (-not $InstallDir) {
1700-
& $fullPSPath -NoLogo -NoProfile -File $fullDotnetInstallPath -Channel $Channel -Version $Version
1701-
} else {
1702-
& $fullPSPath -NoLogo -NoProfile -File $fullDotnetInstallPath -Channel $Channel -Version $Version -InstallDir $InstallDir
1726+
$psArgs = @('-NoLogo', '-NoProfile', '-File', $fullDotnetInstallPath, '-Channel', $Channel, '-Version', $Version)
1727+
1728+
if ($InstallDir) {
1729+
$psArgs += @('-InstallDir', $InstallDir)
17031730
}
1731+
1732+
if ($AzureFeed) {
1733+
$psArgs += @('-AzureFeed', $AzureFeed, '-FeedCredential', $FeedCredential)
1734+
}
1735+
1736+
& $fullPSPath @psArgs
17041737
}
17051738
}
17061739
}

tools/UpdateDotnetRuntime.ps1

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ param (
77
[string]$SDKVersionOverride,
88

99
[Parameter()]
10-
[switch]$UpdateMSIPackaging
10+
[switch]$UpdateMSIPackaging,
11+
12+
[Parameter()]
13+
[string]$RuntimeSourceFeed,
14+
15+
[Parameter()]
16+
[string]$RuntimeSourceFeedKey,
17+
18+
[Parameter()]
19+
[switch]$InteractiveAuth
1120
)
1221

1322
<#
@@ -130,6 +139,14 @@ function Update-CsprojFile([string] $path, $values) {
130139
}
131140

132141
function Get-DotnetUpdate {
142+
if ($SDKVersionOverride) {
143+
return @{
144+
ShouldUpdate = $true
145+
NewVersion = $SDKVersionOverride
146+
Message = $null
147+
}
148+
}
149+
133150
try {
134151
$dotnetMetadataPath = "$PSScriptRoot/../DotnetRuntimeMetadata.json"
135152
$nextChannel = (Get-Content $dotnetMetadataPath -Raw | ConvertFrom-Json).sdk.nextChannel
@@ -180,17 +197,38 @@ if ($dotnetUpdate.ShouldUpdate) {
180197

181198
Find-Dotnet
182199

183-
if (-not (Get-PackageSource -Name 'dotnet5' -ErrorAction SilentlyContinue)) {
184-
$nugetFeed = ([xml](Get-Content .\nuget.config -Raw)).Configuration.packagesources.add | Where-Object { $_.Key -eq 'dotnet5' } | Select-Object -ExpandProperty Value
185-
Register-PackageSource -Name 'dotnet5' -Location $nugetFeed -ProviderName NuGet
186-
Write-Verbose -Message "Register new package source 'dotnet5'" -verbose
200+
$addDotnet5Source = (-not (Get-PackageSource -Name 'dotnet5' -ErrorAction SilentlyContinue))
201+
$addDotnet5InternalSource = (-not (Get-PackageSource -Name 'dotnet5-internal' -ErrorAction SilentlyContinue))
202+
203+
if ($addDotnet5Source -or $addDotnet5InternalSource) {
204+
$nugetFileSources = ([xml](Get-Content .\nuget.config -Raw)).Configuration.packagesources.add
205+
206+
if ($addDotnet5Source) {
207+
$dotnet5Feed = $nugetFileSources | Where-Object { $_.Key -eq 'dotnet5' } | Select-Object -ExpandProperty Value
208+
Register-PackageSource -Name 'dotnet5' -Location $dotnet5Feed -ProviderName NuGet
209+
Write-Verbose -Message "Register new package source 'dotnet5'" -verbose
210+
}
211+
212+
if ($addDotnet5InternalSource -and $InteractiveAuth) {
213+
# This NuGet feed is for internal to Microsoft use only.
214+
$dotnet5InternalFeed = 'https://pkgs.dev.azure.com/dnceng/internal/_packaging/dotnet5-internal/nuget/v3/index.json'
215+
$updatedNugetFile = (Get-Content .\nuget.config -Raw) -replace "</packageSources>", " <add key=`"dotnet5-internal`" value=`"$dotnet5InternalFeed`" />`r`n </packageSources>"
216+
$updatedNugetFile | Out-File .\nuget.config -Force
217+
Register-PackageSource -Name 'dotnet5-internal' -Location $dotnet5InternalFeed -ProviderName NuGet
218+
Write-Verbose -Message "Register new package source 'dotnet5-internal'" -verbose
219+
}
187220
}
188221

189222
## Install latest version from the channel
190223

191224
$sdkVersion = if ($SDKVersionOverride) { $SDKVersionOverride } else { $dotnetUpdate.NewVersion }
192225

193-
Install-Dotnet -Channel "$Channel" -Version $sdkVersion
226+
if (-not $RuntimeSourceFeed) {
227+
Install-Dotnet -Channel "$Channel" -Version $sdkVersion
228+
}
229+
else {
230+
Install-Dotnet -Channel "$Channel" -Version $sdkVersion -AzureFeed $RuntimeSourceFeed -FeedCredential $RuntimeSourceFeedKey
231+
}
194232

195233
Write-Verbose -Message "Installing .NET SDK completed." -Verbose
196234

@@ -224,7 +262,7 @@ if ($dotnetUpdate.ShouldUpdate) {
224262
Import-Module "$PSScriptRoot/../build.psm1" -Force
225263
Import-Module "$PSScriptRoot/packaging" -Force
226264
Start-PSBootstrap -Package
227-
Start-PSBuild -Clean -Configuration Release -CrossGen
265+
Start-PSBuild -Clean -Configuration Release -CrossGen -InteractiveAuth:$InteractiveAuth
228266

229267
try {
230268
Start-PSPackage -Type msi -SkipReleaseChecks -InformationVariable wxsData

0 commit comments

Comments
 (0)