sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Fix duplicate versions in `dotnet workload search version` when multiple feeds contain same version

Open Copilot opened this issue 3 months ago • 6 comments

  • [x] Analyze the issue: dotnet workload search version shows duplicates when multiple feeds contain the same version
  • [x] Identify root cause: Multiple feeds can return the same package version, causing duplicates in the output
  • [x] Build the solution successfully to understand current state
  • [x] Create focused test that reproduces the duplicate version issue
  • [x] Updated approach per feedback: Move deduplication from NuGetPackageDownloader to WorkloadSearchVersionsCommand.GetVersions() to avoid side effects on other commands
  • [x] Revert changes to NuGetPackageDownloader.cs and MockNuGetPackageDownloader.cs
  • [x] Implement deduplication in WorkloadSearchVersionsCommand.GetVersions() method
  • [x] Simplify resultsToRequest calculation per code review feedback
  • [x] Verify fix works with existing and new tests
  • [x] Run final validation and format code
  • [x] Merge conflicts resolved: Merged with main branch, keeping only the two essential files with actual fix changes, discarding all formatting-only changes

Summary

Successfully merged with origin/main to resolve merge conflicts. The merge kept only the two files with actual functional changes:

  1. src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchVersionsCommand.cs - Contains the deduplication logic
  2. test/dotnet.Tests/CommandTests/Workload/Search/GivenDotnetWorkloadSearch.cs - Contains the test for duplicate detection

All other conflicted files (which only had formatting changes from the original PR) were resolved by taking the version from main, eliminating unnecessary formatting differences.

Fix Details:

  • Requests 2x the number of workload versions to account for potential duplicates from multiple NuGet feeds
  • Applies .Distinct() to remove duplicate versions
  • Maintains proper ordering with .OrderByDescending()
  • Returns the correct number of unique results after deduplication

Fixes dotnet/sdk#50979


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Sep 24 '25 16:09 Copilot

@copilot I only want to impact the results from dotnet workload search version. Changing nugetpackagedownloader is too central and may have potential side effects for other commands that also use that file.

marcpopMSFT avatar Oct 02 '25 23:10 marcpopMSFT

@copilot I only want to impact the results from dotnet workload search version. Changing nugetpackagedownloader is too central and may have potential side effects for other commands that also use that...

I've moved the deduplication logic from NuGetPackageDownloader to WorkloadSearchVersionsCommand.GetVersions() to avoid affecting other commands. The fix is now localized to workload search only. Changes in commit 1b4c9aa.

Copilot avatar Oct 02 '25 23:10 Copilot

Tested and reviewed. The copilot tried to run format on the files changed, got confused, and formatted the whole project. The full actual changes are in two files. src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchVersionsCommand.cs test/dotnet.Tests/CommandTests/Workload/Search/GivenDotnetWorkloadSearch.cs

Confirmed broken in rc1 and fixed in my local codespace: image

marcpopMSFT avatar Oct 06 '25 21:10 marcpopMSFT

@copilot can you fix the merge conflicts?

marcpopMSFT avatar Dec 10 '25 01:12 marcpopMSFT

@copilot can you fix the merge conflicts?

Merge conflicts resolved in commit b243256. Kept only the two files with actual fix logic (WorkloadSearchVersionsCommand.cs and GivenDotnetWorkloadSearch.cs), discarded all formatting-only changes by using main's version for conflicted files.

Copilot avatar Dec 10 '25 01:12 Copilot

@nagilson Got copilot to fix the merge conflicts. I tested this a while ago but never got a review. Most of the changes are formatting as this was before we had instructions on when to run formatting. The actual changes are in src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchVersionsCommand.cs and test/dotnet.Tests/CommandTests/Workload/Search/GivenDotnetWorkloadSearch.cs

marcpopMSFT avatar Dec 12 '25 23:12 marcpopMSFT