Fix duplicate versions in `dotnet workload search version` when multiple feeds contain same version
- [x] Analyze the issue:
dotnet workload search versionshows 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
NuGetPackageDownloadertoWorkloadSearchVersionsCommand.GetVersions()to avoid side effects on other commands - [x] Revert changes to
NuGetPackageDownloader.csandMockNuGetPackageDownloader.cs - [x] Implement deduplication in
WorkloadSearchVersionsCommand.GetVersions()method - [x] Simplify
resultsToRequestcalculation 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:
src/Cli/dotnet/Commands/Workload/Search/WorkloadSearchVersionsCommand.cs- Contains the deduplication logictest/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 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.
@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.
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:
@copilot can you fix the merge conflicts?
@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.
@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