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



我想卸载.NET 5和.NET 6预览版,只保留最新的.NET 6。

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

在设置/Apps&功能(Windows 10(。

所有SDK都已使用正确的安装实用程序(无zip文件(或Visual演播室

我已卸载Visual Studio,而是使用VSCode。

当前SDK列表:

C:>dotnet --list-sdks
5.0.400 [C:Program Filesdotnetsdk]
6.0.100-preview.7.21379.14 [C:Program Filesdotnetsdk]
6.0.101 [C:Program Filesdotnetsdk]

可卸载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:
C:Program Files (x86)dotnet-core-uninstall>dotnet-core-uninstall --version
1.5.255402+e07a3c995ec2d3cf449d37eb50c87e180da12544

任何关于如何摆脱它们的提示都将不胜感激。

我知道这晚了几个月,但这在谷歌上的排名很高,所以在这里添加答案。

您可以使用dotnet核心卸载工具,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

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

我发现了一个GitHub问题,我从中制作了一个Gist,列出了所有安装的软件,包括任何不可见的软件。

示例

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

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

获取所有包含(区分大小写(.NET AND 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:SOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall",
"HKLM:SOFTWAREMicrosoftWindowsCurrentVersionUninstall"
)
}

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
# 

最新更新