diff --git a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetExeWrapper.cs b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetExeWrapper.cs index e0a1822a7eee..3a3ff89d7c95 100644 --- a/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetExeWrapper.cs +++ b/csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetExeWrapper.cs @@ -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) { @@ -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) @@ -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));