Skip to content

Commit fde527a

Browse files
committed
C#: Ensure that TryRestore provides an explicit nuget sources and make it respect the check nuget feed flag.
1 parent e934562 commit fde527a

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

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

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public NugetPackageRestorer(
5353

5454
public string? TryRestore(string package)
5555
{
56-
if (TryRestorePackageManually(package))
56+
var feeds = feedManager.CheckNugetFeedResponsiveness ? feedManager.ReachableFeeds : feedManager.AllFeeds;
57+
var nugetSources = feedManager.FeedsToDotnetRestoreArgument(feeds);
58+
if (TryRestorePackageManually(package, nugetSources))
5759
{
5860
var packageDir = DependencyManager.GetPackageDirectory(package, missingPackageDirectory.DirInfo);
5961
if (packageDir is not null)
@@ -301,7 +303,7 @@ private void RestoreProjects(IEnumerable<string> projects, out ConcurrentBag<Dep
301303
compilationInfoContainer.CompilationInfos.Add(("Failed project restore with missing package error", nugetMissingPackageFailures.ToString()));
302304
}
303305

304-
private AssemblyLookupLocation? DownloadMissingPackages(IEnumerable<string> usedPackageNames)
306+
private string? GetFallbackNugetSources()
305307
{
306308
IEnumerable<string>? feeds = null;
307309
if (feedManager.CheckNugetFeedResponsiveness || feedManager.HasPrivateRegistryFeeds)
@@ -324,6 +326,13 @@ private void RestoreProjects(IEnumerable<string> projects, out ConcurrentBag<Dep
324326

325327
var nugetSources = feeds is not null ? feedManager.FeedsToDotnetRestoreArgument(feeds) : null;
326328

329+
return nugetSources;
330+
}
331+
332+
private AssemblyLookupLocation? DownloadMissingPackages(IEnumerable<string> usedPackageNames)
333+
{
334+
var nugetSources = GetFallbackNugetSources();
335+
327336
var alreadyDownloadedPackages = usedPackageNames.Select(p => p.ToLowerInvariant());
328337
var alreadyDownloadedLegacyPackages = GetRestoredLegacyPackageNames();
329338

@@ -469,7 +478,7 @@ private static IEnumerable<string> GetRestoredPackageDirectoryNames(DirectoryInf
469478
.Select(d => Path.GetFileName(d).ToLowerInvariant());
470479
}
471480

472-
private bool TryRestorePackageManually(string package, string? nugetSources = null, PackageReferenceSource packageReferenceSource = PackageReferenceSource.SdkCsProj, bool tryPrereleaseVersion = true)
481+
private bool TryRestorePackageManually(string package, string? nugetSources, PackageReferenceSource packageReferenceSource = PackageReferenceSource.SdkCsProj, bool tryPrereleaseVersion = true)
473482
{
474483
logger.LogInfo($"Restoring package {package}...");
475484
using var tempDir = new TemporaryDirectory(

0 commit comments

Comments
 (0)