dotnet / cli-lab

A guided tool will be provided to enable the controlled clean up of a system such that only the desired versions of the Runtime and SDKs remain.
MIT License
620 stars 56 forks source link

.NET Core SDKs: 8.0.100-rc.2.23502.2 (arm64) [Cannot uninstall version 8.0.0 and above] #273

Closed tibinthomas closed 6 months ago

tibinthomas commented 11 months ago

.NET Core SDKs: 8.0.100-rc.2.23502.2 (arm64) [Cannot uninstall version 8.0.0 and above]

jrdodds commented 11 months ago

.NET 8.0 has been released today (November 14, 2023) and the .NET uninstall tool (dotnet-core-uninstall) doesn't handle SDK versions 8 and above.

Steps to Reproduce

Running the command

dotnet-core-uninstall dry-run --sdk 8.0.100-rc.2.23502.2

produces the message

Uninstallation not allowed. This tool cannot uninstall .NET Core SDKs with version 8.0.0 or above.
penkin commented 11 months ago

Anyone have a solution to this?

jrdodds commented 11 months ago

Steps for manually deleting an SDK or Runtime:

  1. Run dotnet --info and note the base path, e.g.
    Base Path:   /usr/local/share/dotnet/sdk/8.0.100/
  2. To remove an SDK:
    • The dotnet/sdk directory (e.g. /usr/local/share/dotnet/sdk) will have a sub-directory for each installed sdk version.
    • Within the dotnet/sdk directory, delete the sdk version directory (e.g. 8.0.100-rc.2.23502.2).
  3. To remove a runtime:
    • The dotnet/shared directory (e.g. /usr/local/share/dotnet/shared) will have sub-directories for different runtimes (e.g. Microsoft.AspNetCore.App and Microsoft.NETCore.App). Each runtime directory will have version sub-directories.
    • For each relevant runtime, delete the version directory.
thomasgauvin commented 11 months ago

Running into the same issue, this is an important functionality required to test forwards compatibility with .NET 8

np422 commented 10 months ago

I have about 85 windows servers that I need to maintain with the latest version of dotnet SDK/hosting bundle.

I am not very amused by the conecept of in logging in and doing the uninstall interactively on all of them.

The dotnet-core-uninstall has been a very useful tool up until v8 was released.

I have ended up using the powershell script below instead as of lately, may be useful if someone else find themselves in a similar situation.

Be careful, the script is a blunt tool, as at your own risk - althoug it gets the job done for me.

$softwareName = '.NET'
$searchString = "*$softwareName*"
$msiExecPath = Join-Path -Path $env:SystemRoot -ChildPath 'system32' | Join-Path -ChildPath 'msiexec.exe'

function Find-DotNetCoreInstall {
    param (
        $softName = $softwareName
    )
    $software = @( 
        'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*',
        'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*'
    )
    $searchString = "*$softwareName**"
    $allDotNetItems = Get-ItemProperty $software | Where-Object {$_.displayName -like $searchString} | Select-Object DisplayName,DisplayVersion,UninstallString
    Write-Output $allDotNetItems
}
$allDotNetItems = Find-DotNetCoreInstall

if($allDotNetItems.count -gt 0) {
    Write-Host "Uninstalling $($allDotNetItems.count) components for $softwareName $version"

    foreach($item in $allDotNetItems) {
        $uninstallString = $item.UninstallString
        $name = $item.DisplayName
        if ($uninstallString -like "MsiExec.exe *") {
            Write-Host "Uninstalling $name version: $($item.displayVersion)"
            $guid = ([regex]'{[A-Z0-9-]+}').Match($uninstallString).Value

            start-process -FilePath $msiExecPath -ArgumentList @("/x$guid", "/passive", "/quiet", "/norestart", "IGNOREDEPENDENCIES=ALL", "/log `"$env:temp\$($name)_Uninstall_$($version).log`"") -Wait
        } 
        else {
            $filepath = ($uninstallString.Split('/')[0]).replace('"','')
            Write-Host "Uninstalling $name version: $($item.displayVersion)"
            Start-Process -FilePath $filepath -ArgumentList @("/uninstall", "/silent") -Wait
        }
    }
}
else {
    Write-Host "There are no installed components of $software $version"
    exit 0
}

$finalCheck = Find-DotNetCoreInstall
if ($finalCheck.count -eq 0){
    Write-Host "All .NET components have been uninstalled"
    exit 0
}
else {
    Write-Host "Error: NOT ALL COMPONENTS uninstalled! `n $finalCheck "
    exit 1
}
durandt commented 9 months ago

+1

Documentation still points to this tool as the only alternative to removing old .NET runtimes and SDKs. https://learn.microsoft.com/en-us/dotnet/core/install/remove-runtime-sdk-versions?pivots=os-macos https://github.com/dotnet/core/issues/1202

harish-venkataramanan-cko commented 8 months ago

Users that don't have permission to delete the folders in such paths currently have no way of uninstalling. Without uninstalling all the dotnet versions, there is no way to work around the issue mentioned here, running around in circles now :(

jrdodds commented 8 months ago

At the time this issue was opened, .NET 8 was in preview. But shortly after this issue was opened, .NET 8 was released.

As it stands now, the dotnet-core-uninstall tool doesn't support the current LTS release (.NET 8) and doesn't support the current preview release (.NET 9).

The source for the dotnet-core-uninstall tool was last updated in December 2022 and looking at the source there appears to be a hard-coded upper limit:

https://github.com/dotnet/cli-lab/blob/86b3ccddf425a7724b9b48f3feabeceb33730546/src/dotnet-core-uninstall/Shared/VSVersioning/VisualStudioSafeVersionsExtractor.cs#L15-L16

But there is a PR from a member of the Microsoft team that is pending review that would advance the supported versions to include v9 - see #268.

baronfel commented 8 months ago

We're aware that this is a long gap, and that macOS users especially don't have another answer for the problem that the uninstall tool solves. The current plan is for @joeloff and I to close out our current tasking and get dedicated time to do a few things in this repo:

We'll update this space with more details as we find out more about that dedicated chunk of time.

jrdodds commented 8 months ago

Thanks @baronfel. That's great news.

baronfel commented 8 months ago

I've logged a new issue detailing the roadmap for the next release(s) of the tool at https://github.com/dotnet/cli-lab/issues/279.

baronfel commented 6 months ago

We've now released a new version of the tool that supports managing .NET 8 installs. Please see the release notes for more details!