diff options
author | Jeremy Kuhne <jeremy.kuhne@microsoft.com> | 2015-04-14 23:58:04 +0300 |
---|---|---|
committer | Jeremy Kuhne <jeremy.kuhne@microsoft.com> | 2015-04-14 23:58:04 +0300 |
commit | f474b4fc39ba2c4fd3fc23210f1bff85523aebd0 (patch) | |
tree | 3b6b5f38699abf68d28f5afe9dc368034fe67368 /dir.targets | |
parent | 4970c7488fccce280157bdbbb4c82e87efcef68d (diff) |
Change the download task to make three attempts before failing.
Diffstat (limited to 'dir.targets')
-rw-r--r-- | dir.targets | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/dir.targets b/dir.targets index 976cfd29c9..6e3e4d4600 100644 --- a/dir.targets +++ b/dir.targets @@ -4,7 +4,7 @@ <!-- Inline task to bootstrap the build to enable downloading nuget.exe --> <UsingTask TaskName="DownloadFile" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v12.0.dll"> <ParameterGroup> - <Address ParameterType="System.String" Required="true"/> + <Address ParameterType="System.String" Required="true" /> <FileName ParameterType="System.String" Required="true" /> </ParameterGroup> <Task> @@ -17,7 +17,30 @@ var tempFile = Path.Combine(directory, Path.GetRandomFileName()); var client = new System.Net.WebClient(); - client.DownloadFile(Address, tempFile); + var tryCount = 1; + var maxTries = 3; + + while (tryCount <= maxTries) + { + try + { + Log.LogMessage("Attempting to download {0}...", Address); + client.DownloadFile(Address, tempFile); + break; + } + catch (System.Net.WebException e) + { + tryCount++; + if (tryCount > maxTries) + { + throw; + } + else + { + Log.LogMessage(MessageImportance.High, "Download failed, retrying: {0}", e.Message); + } + } + } try { |