Skip to content

Conversation

@tamasvajk
Copy link
Contributor

When dotnet core projects are restored, the dependency manager precisely tracks the referenced package folders. The fallback restore logic ignored the precise usage list and instead considered all subfolders in the restore location to be referenced, even though not all subfolders were added to the dependency list. This meant that packages downloaded in partially successful restores were available on disk, but not added to the dependency list by the normal restore process, and skipped by the fallback restore process. This commit fixes this problem by ensuring that the fallback restore logic doesn't consider all subfolders in the restore location to be referenced, but only those that were added to the dependency list by the normal restore process.

When dotnet core projects are restored, the dependency manager precisely tracks the referenced package folders. The fallback restore logic ignored the precise usage list and instead considered all subfolders in the restore location to be referenced, even though not all subfolders were added to the dependency list. This meant that packages downloaded in partially successful restores were available on disk, but not added to the dependency list by the normal restore process, and skipped by the fallback restore process. This commit fixes this problem by ensuring that the fallback restore logic doesn't consider all subfolders in the restore location to be referenced, but only those that were added to the dependency list by the normal restore process.
@github-actions github-actions bot added the C# label Mar 18, 2025
@tamasvajk
Copy link
Contributor Author

DCA shows quite a big change in alert count. I'll do a traced-buildless comparison too.

@tamasvajk tamasvajk marked this pull request as ready for review March 19, 2025 08:33
Copilot AI review requested due to automatic review settings March 19, 2025 08:33
@tamasvajk tamasvajk requested a review from a team as a code owner March 19, 2025 08:33
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes the fallback restore logic in C# so that only dependency-listed packages are considered during fallback restore. It updates method signatures and parameter usage for downloading missing packages and refactors logging and return values in the package directory name method.

  • Changed call signatures to pass a used package names list.
  • Renamed and refactored the method that logs and returns package directories.
Comments suppressed due to low confidence (1)

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

  • [nitpick] The method GetAllUsedPackageDirNames logs packages as unused while returning those that are used, indicating a mismatch between the method name and its internal logging. Consider adjusting the log messages or the returned values for consistency.
.ForEach(package => logger.LogDebug("Unused package: {package.package}"));

Tip: If you use Visual Studio Code, you can request a review from Copilot before you push from the "Source Control" tab. Learn more

{
// todo: we could also check the reachability of the inherited nuget feeds, but to use those in the fallback we would need to handle authentication too.
var unresponsiveMissingPackageLocation = DownloadMissingPackagesFromSpecificFeeds(explicitFeeds);
var unresponsiveMissingPackageLocation = DownloadMissingPackagesFromSpecificFeeds([], explicitFeeds);
Copy link

Copilot AI Mar 19, 2025

Choose a reason for hiding this comment

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

Passing an empty array for usedPackageNames on line 112 may bypass filtering based on the dependency list. Verify that this argument value correctly reflects the intended set of used package names.

Suggested change
var unresponsiveMissingPackageLocation = DownloadMissingPackagesFromSpecificFeeds([], explicitFeeds);
var usedPackageNames = GetAllUsedPackageDirNames(dependencies);
var unresponsiveMissingPackageLocation = DownloadMissingPackagesFromSpecificFeeds(usedPackageNames, explicitFeeds);

Copilot uses AI. Check for mistakes.
michaelnebel
michaelnebel previously approved these changes Mar 19, 2025
Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@michaelnebel michaelnebel left a comment

Choose a reason for hiding this comment

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

Still LGTM!

@tamasvajk tamasvajk merged commit 03f93dd into github:main Mar 24, 2025
17 checks passed
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.

2 participants