Skip to content

C#: Use feed management in the remaining restore flows. - #22041

Merged
michaelnebel merged 11 commits into
github:mainfrom
michaelnebel:csharp/morefeedmanageruses
Aug 19, 2026
Merged

C#: Use feed management in the remaining restore flows.#22041
michaelnebel merged 11 commits into
github:mainfrom
michaelnebel:csharp/morefeedmanageruses

Conversation

@michaelnebel

@michaelnebel michaelnebel commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

The primary purpose of this PR is to use the newly introduced feed manager in more of the package restore flows.

To achieve this we are

  • Re-factoring a bit more functionality into the feed manager to avoid arguments being passed around in the NuGet package restorer.
  • Use the feed manager in DowloadMissingPackages. This also somewhat simplifies the restore logic as we no longer create a dedicated nuget.config file in fallback scenarios, but instead we supply feeds directly via the command line. Furthermore, if NuGet feed responsiveness checking is disabled we use all feeds when attempting to download missing packages (this will include private registries as well).
  • Use the feed manager in the TryRestore method, which can be used to restore individual packages. The logic has been changed slightly here compared to earlier as we will attempt to use the feeds detected in the source directory (instead of those in the temporary directory).

With the changes in this PR, all restore like flows specify the feeds directly via the command line (unless NuGet feed checking is disabled and no private registries are configured). That is, as a follow up we can attempt the remove the timeout fallback and instead just always use reachable feeds.

Testing

  • DCA looks good.
  • A QA run was made and can be seen here. Note, that this is only available internally, but making the link available for the review'er. The QA run appears to be uneventful.

@github-actions github-actions Bot added the C# label Jun 24, 2026
@michaelnebel
michaelnebel force-pushed the csharp/morefeedmanageruses branch from 25ade27 to afe8f07 Compare June 24, 2026 10:58
@michaelnebel
michaelnebel force-pushed the csharp/morefeedmanageruses branch 5 times, most recently from 29a859a to 036f75c Compare June 24, 2026 13:47
@michaelnebel
michaelnebel force-pushed the csharp/morefeedmanageruses branch from 036f75c to 86fc08e Compare June 25, 2026 11:06
@michaelnebel
michaelnebel force-pushed the csharp/morefeedmanageruses branch 3 times, most recently from 4690d92 to 6ee50ce Compare June 30, 2026 13:05
@michaelnebel
michaelnebel force-pushed the csharp/morefeedmanageruses branch from 43aaec6 to fde527a Compare June 30, 2026 14:21
@michaelnebel michaelnebel changed the title C#: Improve package download logic. C#: Use feed management in the remaining restore flows. Jul 1, 2026
@michaelnebel
michaelnebel force-pushed the csharp/morefeedmanageruses branch 2 times, most recently from bbc01c9 to b0eaf49 Compare July 17, 2026 13:19
@michaelnebel
michaelnebel force-pushed the csharp/morefeedmanageruses branch from b0eaf49 to a66f82e Compare August 11, 2026 11:56

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.

Pull request overview

Centralizes NuGet feed selection in FeedManager across remaining C# dependency restore flows.

Changes:

  • Adds lazy feed discovery and reachability management.
  • Passes feeds directly to restore commands.
  • Removes fallback nuget.config generation.
Show a summary per file
File Description
2026-07-17-nuget-package-restore.md Documents restore changes.
Semmle.Extraction.Tests/DotNet.cs Updates restore argument tests.
PackagesConfigRestorer.cs Uses managed feed selection.
NugetPackageRestorer.cs Migrates remaining restore flows.
IDotNet.cs Removes config-path setting.
FeedManager.cs Centralizes feed state and reachability.
DotNet.cs Removes --configfile handling.

Review details

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Suppressed comments (1)

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

  • The newly introduced unchecked-feed fallback is not exercised by the existing fallback integration tests; they all leave responsiveness checking enabled. Please add coverage that disables feed checking and verifies a missing package is restored through AllFeeds, including the intended configured/private-feed behavior.
            else
            {
                feeds = feedManager.AllFeeds;
            }
  • Files reviewed: 7/7 changed files
  • Comments generated: 3
  • Review effort level: Balanced

Comment thread csharp/extractor/Semmle.Extraction.CSharp.DependencyFetching/FeedManager.cs Outdated
@michaelnebel
michaelnebel requested a review from hvitved August 13, 2026 07:55
@michaelnebel
michaelnebel marked this pull request as ready for review August 13, 2026 07:55
@michaelnebel
michaelnebel requested a review from a team as a code owner August 13, 2026 07:55

@hvitved hvitved 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.

LGTM, some minor comments.

/// <summary>
/// Gets the list of inherited NuGet feeds that are configured in the environment.
/// </summary>
public ImmutableHashSet<string> InheritedFeeds => AllFeeds.Except(ExplicitFeeds).ToImmutableHashSet();

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.

Would it make the code cleaner if the logic populated this hash set and AllFeed was then defined as the union of ExplicitFields and InheritedFields?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think there is an easy way to calculate InheritedFeeds in another way than AllFeeds\ExplicitFeeds

/// <summary>
/// Gets whether there was a timeout when checking the reachability of the explicitly configured NuGet feeds.
/// </summary>
public bool ExplicitFeedTimeout => lazyReachableExplicitFeeds.Value.Item1;

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.

Could this instead be ReachableExplicitFeeds.Count() == ExplicitFields.Count() and then we can avoid the tuple construction?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately not. The set of ReachableExplicitFeeds are the feeds where we have confirmed that we can connect. That is, ReachableExplicitFeeds doesn't contain feeds where we e.g. get 401/403 errors (or other errors). The timeout boolean only refers to a timeout. This means that we could have ReachableExplicitFeeds.Count() != ExplicitFields.Count() and timeout = false.

There is also a follow up PR for getting rid of the ExplicitFeedTimeout altogether: #22094

---
category: majorAnalysis
---
* Simplified and streamlined the use of NuGet sources when downloading dependencies. In fallback scenarios and specialized package downloads, NuGet sources are now passed directly to `dotnet restore` via `-s`. Furthermore, no `nuget.config` files are created for fallback scenarios, and private registries are used when attempting to download missing packages that were not restored as part of the normal `dotnet restore` process.

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.

The dotnet restore -s change seems like an internal implementation detail that customers should not care about?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We can remove the mention of -s, but I think we need to mention that feeds are provided directly to the restore command (If this change for some reason break something)

hvitved
hvitved previously approved these changes Aug 19, 2026
@michaelnebel

Copy link
Copy Markdown
Contributor Author

@hvitved : Made a small update to the change note. Could you re-approve? 😄

@michaelnebel
michaelnebel merged commit 01755ec into github:main Aug 19, 2026
20 checks passed
@michaelnebel
michaelnebel deleted the csharp/morefeedmanageruses branch August 19, 2026 12:59
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.

4 participants