From 7ebb57c246eb450ee5bab800fa8197fd4c7dfcf9 Mon Sep 17 00:00:00 2001 From: nitheeshgovind Date: Sat, 27 Jun 2026 15:55:29 +0530 Subject: [PATCH] improve sorting of installed versions when uninstalling dotnet version --- .../src/extension.ts | 44 +++++++++++-------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/vscode-dotnet-runtime-extension/src/extension.ts b/vscode-dotnet-runtime-extension/src/extension.ts index b5d7a0e043..51617d0ae4 100644 --- a/vscode-dotnet-runtime-extension/src/extension.ts +++ b/vscode-dotnet-runtime-extension/src/extension.ts @@ -575,27 +575,35 @@ export function activate(vsCodeContext: vscode.ExtensionContext, extensionContex const dotnetUninstallPublicRegistration = vscode.commands.registerCommand(`${commandPrefix}.${commandKeys.uninstallPublic}`, async () => { - const existingInstalls: InstallRecord[] = await InstallTrackerSingleton.getInstance(globalEventStream, vsCodeContext.globalState).getExistingInstalls(directoryProviderFactory( - 'runtime', vsCodeContext.globalStoragePath)); - - const menuItems = existingInstalls?.sort( - function (x: InstallRecord, y: InstallRecord): number + 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++) { - if (x.dotnetInstall.installMode === y.dotnetInstall.installMode) + const difference = (xParts[index] ?? 0) - (yParts[index] ?? 0); + if (difference !== 0) { - return x.dotnetInstall.version.localeCompare(y.dotnetInstall.version); + return difference; } - return x.dotnetInstall.installMode.localeCompare(y.dotnetInstall.installMode); - })?.map(install => - { - return { - label: `.NET ${(install.dotnetInstall.installMode === 'sdk' ? 'SDK' : install.dotnetInstall.installMode === 'runtime' ? 'Runtime' : 'ASP.NET Core Runtime')} ${install.dotnetInstall.version}`, - description: `${install.dotnetInstall.architecture ?? ''} | ${install.dotnetInstall.isGlobal ? 'machine-wide' : 'vscode-local'}`, - detail: install.installingExtensions.some(x => x !== null) ? `Used by ${install.installingExtensions.join(', ')}` : ``, - iconPath: install.dotnetInstall.isGlobal ? new vscode.ThemeIcon('shield') : new vscode.ThemeIcon('trash'), - internalId: install.dotnetInstall.installId - } - }); + } + return 0; + }; + + const existingInstalls: InstallRecord[] = await InstallTrackerSingleton.getInstance(globalEventStream, vsCodeContext.globalState).getExistingInstalls(directoryProviderFactory( + 'runtime', vsCodeContext.globalStoragePath)); + + const menuItems = existingInstalls?.sort(compareVersions)?.map(install => + { + return { + label: `.NET ${(install.dotnetInstall.installMode === 'sdk' ? 'SDK' : install.dotnetInstall.installMode === 'runtime' ? 'Runtime' : 'ASP.NET Core Runtime')} ${install.dotnetInstall.version}`, + description: `${install.dotnetInstall.architecture ?? ''} | ${install.dotnetInstall.isGlobal ? 'machine-wide' : 'vscode-local'}`, + detail: install.installingExtensions.some(x => x !== null) ? `Used by ${install.installingExtensions.join(', ')}` : ``, + iconPath: install.dotnetInstall.isGlobal ? new vscode.ThemeIcon('shield') : new vscode.ThemeIcon('trash'), + internalId: install.dotnetInstall.installId + } + }); if ((menuItems?.length ?? 0) < 1) {