@@ -155,12 +155,12 @@ function InitializeDotNetCli([bool]$install, [bool]$createSdkLocationFile) {
155155 # The following code block is protecting against concurrent access so that this function can
156156 # be called in parallel.
157157 if ($createSdkLocationFile ) {
158- do {
158+ do {
159159 $sdkCacheFileTemp = Join-Path $ToolsetDir $ ([System.IO.Path ]::GetRandomFileName())
160- }
160+ }
161161 until (! (Test-Path $sdkCacheFileTemp ))
162162 Set-Content - Path $sdkCacheFileTemp - Value $dotnetRoot
163-
163+
164164 try {
165165 Rename-Item - Force - Path $sdkCacheFileTemp ' sdk.txt'
166166 } catch {
@@ -188,7 +188,33 @@ function GetDotNetInstallScript([string] $dotnetRoot) {
188188 if (! (Test-Path $installScript )) {
189189 Create- Directory $dotnetRoot
190190 $ProgressPreference = ' SilentlyContinue' # Don't display the console progress UI - it's a huge perf hit
191- Invoke-WebRequest " https://dot.net/$dotnetInstallScriptVersion /dotnet-install.ps1" - OutFile $installScript
191+
192+ $maxRetries = 5
193+ $retries = 1
194+
195+ $uri = " https://dot.net/$dotnetInstallScriptVersion /dotnet-install.ps1"
196+
197+ while ($true ) {
198+ try {
199+ Write-Host " GET $uri "
200+ Invoke-WebRequest $uri - OutFile $installScript
201+ break
202+ }
203+ catch {
204+ Write-Host " Failed to download '$uri '"
205+ Write-Error $_.Exception.Message - ErrorAction Continue
206+ }
207+
208+ if (++ $retries -le $maxRetries ) {
209+ $delayInSeconds = [math ]::Pow(2 , $retries ) - 1 # Exponential backoff
210+ Write-Host " Retrying. Waiting for $delayInSeconds seconds before next attempt ($retries of $maxRetries )."
211+ Start-Sleep - Seconds $delayInSeconds
212+ }
213+ else {
214+ throw " Unable to download file in $maxRetries attempts."
215+ }
216+
217+ }
192218 }
193219
194220 return $installScript
@@ -198,12 +224,12 @@ function InstallDotNetSdk([string] $dotnetRoot, [string] $version, [string] $arc
198224 InstallDotNet $dotnetRoot $version $architecture
199225}
200226
201- function InstallDotNet ([string ] $dotnetRoot ,
202- [string ] $version ,
203- [string ] $architecture = ' ' ,
204- [string ] $runtime = ' ' ,
205- [bool ] $skipNonVersionedFiles = $false ,
206- [string ] $runtimeSourceFeed = ' ' ,
227+ function InstallDotNet ([string ] $dotnetRoot ,
228+ [string ] $version ,
229+ [string ] $architecture = ' ' ,
230+ [string ] $runtime = ' ' ,
231+ [bool ] $skipNonVersionedFiles = $false ,
232+ [string ] $runtimeSourceFeed = ' ' ,
207233 [string ] $runtimeSourceFeedKey = ' ' ) {
208234
209235 $installScript = GetDotNetInstallScript $dotnetRoot
@@ -298,7 +324,7 @@ function InitializeVisualStudioMSBuild([bool]$install, [object]$vsRequirements =
298324 $vsMajorVersion = $vsMinVersion.Major
299325 $xcopyMSBuildVersion = " $vsMajorVersion .$ ( $vsMinVersion.Minor ) .0-alpha"
300326 }
301-
327+
302328 $vsInstallDir = $null
303329 if ($xcopyMSBuildVersion.Trim () -ine " none" ) {
304330 $vsInstallDir = InitializeXCopyMSBuild $xcopyMSBuildVersion $install
0 commit comments