Skip to content

Commit

Permalink
Merge pull request github#16660 from tamasvajk/buildless/nuget-exe
Browse files Browse the repository at this point in the history
C#: Prefer downloading nuget.exe over local instances
  • Loading branch information
tamasvajk authored Jun 4, 2024
2 parents a83d500 + f4d3756 commit c06df55
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,15 @@ private string ResolveNugetExe()
return envVarPath;
}

try
{
return DownloadNugetExe(fileProvider.SourceDir.FullName);
}
catch (Exception exc)
{
logger.LogInfo($"Download of nuget.exe failed: {exc.Message}");
}

var nugetExesInRepo = fileProvider.NugetExes;
if (nugetExesInRepo.Count > 1)
{
Expand All @@ -119,7 +128,7 @@ private string ResolveNugetExe()
return nugetPath;
}

return DownloadNugetExe(fileProvider.SourceDir.FullName);
throw new Exception("Could not find or download nuget.exe.");
}

private string DownloadNugetExe(string sourceDir)
Expand All @@ -136,17 +145,9 @@ private string DownloadNugetExe(string sourceDir)

Directory.CreateDirectory(directory);
logger.LogInfo("Attempting to download nuget.exe");
try
{
FileUtils.DownloadFile(FileUtils.NugetExeUrl, nuget);
logger.LogInfo($"Downloaded nuget.exe to {nuget}");
return nuget;
}
catch
{
// Download failed.
throw new FileNotFoundException("Download of nuget.exe failed.");
}
FileUtils.DownloadFile(FileUtils.NugetExeUrl, nuget);
logger.LogInfo($"Downloaded nuget.exe to {nuget}");
return nuget;
}

private bool RunWithMono => !Win32.IsWindows() && !string.IsNullOrEmpty(Path.GetExtension(nugetExe));
Expand Down

0 comments on commit c06df55

Please sign in to comment.