Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix packages.config to project mapping in NuGet.exe #5818

Merged
merged 10 commits into from
May 30, 2024

Conversation

nkolev92
Copy link
Member

@nkolev92 nkolev92 commented May 23, 2024

Bug

Fixes: NuGet/Home#13456

Regression? Last working version:

Description

The implementation for PC vulnerability checking did not account for the fact that multiple projects might be in the same folder and lead to duplicate packages.config to project mapping.

This fixes that and adds test cases in both nuget.exe restore and msbuild -t:restore.

I've add some in line comments to aid with reviewing.

Please note that this will be patched in 6.10, so take that into consideration when reviewing (ie. focus on correctness, extra clean-up can be done as follow-up and review the tests for correctness).

PR Checklist

  • PR has a meaningful title

  • PR has a linked issue.

  • Described changes

  • Tests

    • Automated tests added
    • OR
    • Test exception
    • OR
    • N/A
  • Documentation

    • Documentation PR or issue filled
    • OR
    • N/A

Dictionary<PackageReference, List<string>> packageReferenceToProjects = new(PackageReferenceComparer.Instance);

foreach (string configFile in packageRestoreInputs.PackagesConfigFiles)
foreach (string configFile in packageRestoreInputs.PackagesConfigFiles.Distinct())
Copy link
Member Author

Choose a reason for hiding this comment

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

Ensure we don't process the same config twice.

There's more performant ways of doing but:

  1. It's NuGet.exe, so this cost is not everywhere and very minor.
  2. More code = more risk, potentially more challenges getting approval.

@nkolev92 nkolev92 force-pushed the dev-nkolev92-fixPCtoProjectMapping branch from 834f1b8 to 0b08ee6 Compare May 28, 2024 22:57
@nkolev92 nkolev92 changed the title Fix PC to project mapping Fix packages.config to project mapping in NuGet.exe - add tests for NuGet.exe and MSBuild -t:restore May 28, 2024
@nkolev92 nkolev92 changed the title Fix packages.config to project mapping in NuGet.exe - add tests for NuGet.exe and MSBuild -t:restore Fix packages.config to project mapping in NuGet.exe May 28, 2024
@@ -276,24 +276,24 @@ private async Task<IReadOnlyList<RestoreSummary>> PerformNuGetV2RestoreAsync(Pac

if (packageRestoreInputs.RestoringWithSolutionFile)
{
Dictionary<string, string> configToProjectPath = GetPackagesConfigToProjectPath(packageRestoreInputs);
Dictionary<string, HashSet<string>> configToProjectPath = GetPackagesConfigToProjectsPath(packageRestoreInputs);
Copy link
Member Author

Choose a reason for hiding this comment

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

While multiple projects to 1 packages.config is not recommended, it is obviously something that does happen, and I don't want to rock the boat in a patch release, so the fix is to just handle that scenario.

https://github.com/NuGet/Client.Engineering/issues/2851 covers more.

@nkolev92 nkolev92 marked this pull request as ready for review May 28, 2024 23:11
@nkolev92 nkolev92 requested a review from a team as a code owner May 28, 2024 23:11
martinrrm
martinrrm previously approved these changes May 28, 2024
@nkolev92 nkolev92 dismissed stale reviews from zivkan and martinrrm via 0ffdb5a May 29, 2024 21:54
@nkolev92 nkolev92 force-pushed the dev-nkolev92-fixPCtoProjectMapping branch from 395167e to 0ffdb5a Compare May 29, 2024 21:54
@nkolev92 nkolev92 requested review from zivkan and martinrrm May 29, 2024 22:20
@nkolev92
Copy link
Member Author

Blocked by some restore issues.
Fix for that in #5827.

@nkolev92 nkolev92 force-pushed the dev-nkolev92-fixPCtoProjectMapping branch from e35086b to 547267d Compare May 29, 2024 23:36
@nkolev92 nkolev92 merged commit 7f48b33 into dev May 30, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants