Skip to content

improve sorting of installed versions when uninstalling dotnet version#2740

Open
nitheeshgovind wants to merge 1 commit into
dotnet:mainfrom
nitheeshgovind:main
Open

improve sorting of installed versions when uninstalling dotnet version#2740
nitheeshgovind wants to merge 1 commit into
dotnet:mainfrom
nitheeshgovind:main

Conversation

@nitheeshgovind

Copy link
Copy Markdown

When the command "Uninstall .NET" is selected, the displayed versions are not sorted based on the version numbers.
#2642

Root Cause

localeCompare was used which did not sort the numbers correctly.

Changes

Added a new compareVersion function which splits the version into integers and compares each index.

const compareVersions = (x: InstallRecord, y: InstallRecord): number =>
        {
            const xParts = x.dotnetInstall.version.split('.').map(part => Number(part.split('-')[0]));
            const yParts = y.dotnetInstall.version.split('.').map(part => Number(part.split('-')[0]));
            const length = Math.max(xParts.length, yParts.length);
            for (let index = 0; index < length; index++)
            {
                const difference = (xParts[index] ?? 0) - (yParts[index] ?? 0);
                if (difference !== 0)
                {
                    return difference;
                }
            }
            return 0;
        };

I also thought about creating a new function in VersionUtilities under the runtime-library, but thought to check first.
Let me know if it is ok.

@nitheeshgovind

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant