当卸载工具无法识别 .NET SDK 预览版和旧版本时,如何卸载它们

Sim*_*bak 11 .net uninstallation .net-core

我想卸载 .NET 5 和 .NET 6 预览版 - 并仅保留最新的 .NET 6。

但是,卸载实用程序只允许我卸载我想要保留的版本。

旧版本也不会在“设置/应用程序和功能”(Windows 10) 中删除。

所有 SDK 均已使用正确的安装实用程序(无 zip 文件)或通过 Visual Studio 安装。

我已经卸载了 Visual Studio - 我改用 VSCode。

当前SDK列表:

C:\>dotnet --list-sdks

5.0.400 [C:\Program Files\dotnet\sdk]
6.0.100-preview.7.21379.14 [C:\Program Files\dotnet\sdk]
6.0.101 [C:\Program Files\dotnet\sdk]
Run Code Online (Sandbox Code Playgroud)

可卸载的 SDK 列表(使用卸载实用程序):

C:\Program Files (x86)\dotnet-core-uninstall>dotnet-core-uninstall list

.NET Core SDKs:
  6.0.101  x64    [Used by Visual Studio. Specify individually or use --force to remove]

.NET Core Runtimes:

ASP.NET Core Runtimes:

.NET Core Runtime & Hosting Bundles:

Run Code Online (Sandbox Code Playgroud)
C:\Program Files (x86)\dotnet-core-uninstall>dotnet-core-uninstall --version
1.5.255402+e07a3c995ec2d3cf449d37eb50c87e180da12544
Run Code Online (Sandbox Code Playgroud)

非常感谢任何有关如何摆脱它们的提示。

Mar*_*rco 6

我知道这已经晚了几个月了,但这最终在谷歌上的排名相当高,所以只是在这里添加答案。

您可以使用 dotnet-core-uninstall 工具,https://learn.microsoft.com/en-us/dotnet/core/additional-tools/uninstall-tool ?tabs=windows

并且可以运行: dotnet-core-uninstall remove --all-previews-but-latest 如果您只想删除预览/保留 .Net 5,您的问题只是保留 .Net 6,因此您可以使用--all-below 6.0.101 --sdk

您可以通过将其添加到命令中来进行试运行(dry-run 和 Whatif 是同义词,您可以使用其中之一): dotnet-core-uninstall whatif --all-below 6.0.101 --sdk

  • 你读过这个问题吗?OP已经知道卸载工具了。 (9认同)

Max*_*Max 5

我发现了一个GitHub Issue,从中我制作了一个要点,其中列出了所有已安装的软件,包括任何不可见的软件。

例子

获取包含(区分大小写).NET 的所有软件
Get-Installed -Name .NET

获取包含(区分大小写).NET 和 3.1.10 的所有软件
Get-Installed -Name .NET | Where-Object {$_.DisplayName.Contains("3.1.10")}

获取包含(区分大小写).NET 和 3.1.10 的所有软件并删除该软件
Get-Installed -Name .NET | Where-Object {$_.DisplayName.Contains("3.1.10")} | Select -Expand PsChildName | Remove-Installed

function Get-Installed {
    [CmdletBinding()]
    param (
        # The name of the software
        [Parameter(Mandatory = $true)]
        [string] $Name
    )
    
    begin {
        $PATHS = @(
            "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
            "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
        )

    }
    
    process {
        $installed = $null
        ForEach ($path in $PATHS) {
            $installed += Get-ChildItem -Path $path |
            ForEach-Object { Get-ItemProperty $_.PSPath } |
            Where-Object { $null -ne $_.DisplayName -and $_.DisplayName.Contains($Name) } |
            Select-Object DisplayName, DisplayVersion, PSChildName |
            Sort-Object -Property DisplayName
        }
        $installed
    }
    
    end {
        
    }
}

function Remove-Installed {
    [CmdletBinding()]
    param (
        [Parameter(Mandatory = $true, ValueFromPipeline = $true)]
        $Guid
    )
    
    process {
        Write-Verbose "Removing $Guid"
        $a = "/x " + $Guid
        Start-Process msiexec -Wait -ArgumentList $a
    }
    
}

# Examples
#
# Get ALL software containing (case-SENSITIVE) .NET
# Get-Installed -Name .NET  
# 
# Get ALL software containing (case-SENSITIVE) .NET AND 3.1.10
# Get-Installed -Name .NET | Where-Object {$_.DisplayName.Contains("3.1.10")} 
#
# Get ALL software containing (case-SENSITIVE) .NET AND 3.1.10 AND Remove those software
# Get-Installed -Name .NET | Where-Object {$_.DisplayName.Contains("3.1.10")} | Select -Expand PsChildName | Remove-Installed
# 
Run Code Online (Sandbox Code Playgroud)