Skip to content

Commit a8dde15

Browse files
committed
C#: Only provide feeds on command line if Dependabot proxy is enabled
1 parent 6b15f77 commit a8dde15

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Diff for: csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/NugetPackageRestorer.cs

+15-3
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,21 @@ private IEnumerable<string> RestoreSolutions(out DependencyContainer dependencie
262262
/// <param name="projects">A list of paths to project files.</param>
263263
private void RestoreProjects(IEnumerable<string> projects, HashSet<string>? configuredSources, out ConcurrentBag<DependencyContainer> dependencies)
264264
{
265-
var sources = configuredSources ?? new();
266-
sources.Add(PublicNugetOrgFeed);
267-
this.dependabotProxy?.RegistryURLs.ForEach(url => sources.Add(url));
265+
// Conservatively, we only set this to a non-null value if a Dependabot proxy is enabled.
266+
// This ensures that we continue to get the old behaviour where feeds are taken from
267+
// `nuget.config` files instead of the command-line arguments.
268+
HashSet<string>? sources = null;
269+
270+
if (this.dependabotProxy != null)
271+
{
272+
// If the Dependabot proxy is configured, then our main goal is to make `dotnet` aware
273+
// of the private registry feeds. However, since providing them as command-line arguments
274+
// to `dotnet` ignores other feeds that may be configured, we also need to add the feeds
275+
// we have discovered from analysing `nuget.config` files.
276+
sources = configuredSources ?? new();
277+
sources.Add(PublicNugetOrgFeed);
278+
this.dependabotProxy?.RegistryURLs.ForEach(url => sources.Add(url));
279+
}
268280

269281
var successCount = 0;
270282
var nugetSourceFailures = 0;

0 commit comments

Comments
 (0)