@@ -184,7 +184,14 @@ function InstallDotNetSdk([string] $dotnetRoot, [string] $version, [string] $arc
184184 InstallDotNet $dotnetRoot $version $architecture
185185}
186186
187- function InstallDotNet ([string ] $dotnetRoot , [string ] $version , [string ] $architecture = " " , [string ] $runtime = " " , [bool ] $skipNonVersionedFiles = $false ) {
187+ function InstallDotNet ([string ] $dotnetRoot ,
188+ [string ] $version ,
189+ [string ] $architecture = " " ,
190+ [string ] $runtime = " " ,
191+ [bool ] $skipNonVersionedFiles = $false ,
192+ [string ] $runtimeSourceFeed = " " ,
193+ [string ] $runtimeSourceFeedKey = " " ) {
194+
188195 $installScript = GetDotNetInstallScript $dotnetRoot
189196 $installParameters = @ {
190197 Version = $version
@@ -195,10 +202,32 @@ function InstallDotNet([string] $dotnetRoot, [string] $version, [string] $archit
195202 if ($runtime ) { $installParameters.Runtime = $runtime }
196203 if ($skipNonVersionedFiles ) { $installParameters.SkipNonVersionedFiles = $skipNonVersionedFiles }
197204
198- & $installScript @installParameters
199- if ($lastExitCode -ne 0 ) {
200- Write-PipelineTelemetryError - Category " InitializeToolset" - Message " Failed to install dotnet cli (exit code '$lastExitCode ')."
201- ExitWithExitCode $lastExitCode
205+ try {
206+ & $installScript @installParameters
207+ }
208+ catch {
209+ Write-PipelineTelemetryError - Category " InitializeToolset" - Message " Failed to install dotnet runtime '$runtime ' from public location."
210+
211+ # Only the runtime can be installed from a custom [private] location.
212+ if ($runtime -and ($runtimeSourceFeed -or $runtimeSourceFeedKey )) {
213+ if ($runtimeSourceFeed ) { $installParameters.AzureFeed = $runtimeSourceFeed }
214+
215+ if ($runtimeSourceFeedKey ) {
216+ $decodedBytes = [System.Convert ]::FromBase64String($runtimeSourceFeedKey )
217+ $decodedString = [System.Text.Encoding ]::UTF8.GetString($decodedBytes )
218+ $installParameters.FeedCredential = $decodedString
219+ }
220+
221+ try {
222+ & $installScript @installParameters
223+ }
224+ catch {
225+ Write-PipelineTelemetryError - Category " InitializeToolset" - Message " Failed to install dotnet runtime '$runtime ' from custom location '$runtimeSourceFeed '."
226+ ExitWithExitCode 1
227+ }
228+ } else {
229+ ExitWithExitCode 1
230+ }
202231 }
203232}
204233
0 commit comments