Skip to content

Commit c06df55

Browse files
authored
Merge pull request github#16660 from tamasvajk/buildless/nuget-exe
C#: Prefer downloading nuget.exe over local instances
2 parents a83d500 + f4d3756 commit c06df55

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetExeWrapper.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,15 @@ private string ResolveNugetExe()
9797
return envVarPath;
9898
}
9999

100+
try
101+
{
102+
return DownloadNugetExe(fileProvider.SourceDir.FullName);
103+
}
104+
catch (Exception exc)
105+
{
106+
logger.LogInfo($"Download of nuget.exe failed: {exc.Message}");
107+
}
108+
100109
var nugetExesInRepo = fileProvider.NugetExes;
101110
if (nugetExesInRepo.Count > 1)
102111
{
@@ -119,7 +128,7 @@ private string ResolveNugetExe()
119128
return nugetPath;
120129
}
121130

122-
return DownloadNugetExe(fileProvider.SourceDir.FullName);
131+
throw new Exception("Could not find or download nuget.exe.");
123132
}
124133

125134
private string DownloadNugetExe(string sourceDir)
@@ -136,17 +145,9 @@ private string DownloadNugetExe(string sourceDir)
136145

137146
Directory.CreateDirectory(directory);
138147
logger.LogInfo("Attempting to download nuget.exe");
139-
try
140-
{
141-
FileUtils.DownloadFile(FileUtils.NugetExeUrl, nuget);
142-
logger.LogInfo($"Downloaded nuget.exe to {nuget}");
143-
return nuget;
144-
}
145-
catch
146-
{
147-
// Download failed.
148-
throw new FileNotFoundException("Download of nuget.exe failed.");
149-
}
148+
FileUtils.DownloadFile(FileUtils.NugetExeUrl, nuget);
149+
logger.LogInfo($"Downloaded nuget.exe to {nuget}");
150+
return nuget;
150151
}
151152

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

0 commit comments

Comments
 (0)