Skip to content

C#: Exclude private registries from NuGet CLI restores - #22948

Open
michaelnebel wants to merge 4 commits into
github:mainfrom
michaelnebel:michaelnebel-nuget-public-feeds
Open

michaelnebel wants to merge 4 commits into
github:mainfrom
michaelnebel:michaelnebel-nuget-public-feeds

Conversation

@michaelnebel

@michaelnebel michaelnebel commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

This PR is mostly generated by CoPilot. We could consider using it instead of completely disabling the use of the NuGet CLI, when private registries are configured (see the referenced PR further down).

However, we still get a lot of error messages in the log, if private registries (and a proxy) are set and if they are a pre-requisite for restoring "anything". @mbg : What is your impression? Should we just exclude private registries from the restore process when using the NuGet CLI or should we completely disable the step?

CoPilots auto generated summary can be seen below.

Summary

Inspired by #22911, keep using the NuGet CLI for packages.config restores instead of disabling it when private registries are configured.

  • Retain applicable non-private feeds while excluding organization-configured private registries, including base-feed replacements, from NuGet CLI sources.
  • Pass an explicit empty source when no eligible feeds remain, preventing implicit fallback to private sources.
  • Leave private registry support in dotnet restore unchanged.
  • Add regression coverage and a C# analysis change note.

michaelnebel and others added 3 commits October 30, 2026 09:08
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@michaelnebel
michaelnebel force-pushed the michaelnebel-nuget-public-feeds branch from d2cbfbc to 3badc71 Compare October 30, 2026 08:08
@michaelnebel
michaelnebel requested a review from mbg October 30, 2026 08:33
@michaelnebel
michaelnebel marked this pull request as ready for review October 30, 2026 08:33
Copilot AI auto review requested due to automatic review settings October 30, 2026 08:33
@michaelnebel
michaelnebel requested a review from a team as a code owner October 30, 2026 08:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Private-feed filtering can let equivalent registry URLs bypass the proxy and incorrectly suppress the NuGet.org fallback, causing otherwise valid package restores to fail.

2 open issues
What changed in this PR

This PR keeps NuGet CLI restores available for C# packages.config files while excluding organization-configured private registries, rather than disabling the restore step. Private registry support in dotnet restore remains unchanged.

Changes:

  • Adds NuGet CLI source filtering and an empty local source when no eligible feeds remain.
  • Routes packages.config restores through the new source-selection method.
  • Adds regression coverage and a C# analysis change note.
File Description
csharp/​ql/​lib/​change-notes/​2026-10-30-nuget-cli-private-registries.md Documents the NuGet CLI restore behavior.
csharp/​extractor/​Semmle.Extraction.Tests/​FeedManager.cs Tests private-feed exclusion, defaults, and empty-source behavior.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​PackagesConfigRestorer.cs Uses the NuGet CLI-specific source selection.
csharp/​extractor/​Semmle.Extraction.CSharp.DependencyFetching/​FeedManager.cs Implements private-registry filtering for NuGet CLI restores.

Review effort: Max (auto)

Comment thread csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/FeedManager.cs Outdated
Comment thread csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/FeedManager.cs Outdated
Filter private candidates and defaults before choosing the fallback, and compare registry URI identities while preserving path case. Add regressions for missing or unreachable folder feeds and equivalent registry URLs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@michaelnebel
michaelnebel force-pushed the michaelnebel-nuget-public-feeds branch from 2312379 to 5f27506 Compare October 30, 2026 10:18
Comment thread csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/FeedManager.cs Dismissed

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants