.NET 卸载工具.NET Uninstall Tool

你可以使用 .NET 卸载工具 (dotnet-core-uninstall) 从系统中删除 .NET SDK 和运行时。The .NET Uninstall Tool (dotnet-core-uninstall) lets you remove .NET SDKs and Runtimes from a system. 可使用选项集合来指定要卸载的版本。A collection of options is available to specify which versions you want to uninstall.

该工具支持 Windows 和 macOS。The tool supports Windows and macOS. 目前不支持 Linux。Linux is currently not supported.

在 Windows 上,该工具只能卸载使用以下安装程序之一安装的 SDK 和运行时:On Windows, the tool can only uninstall SDKs and Runtimes that were installed using one of the following installers:

  • .NET SDK 和运行时安装程序。The .NET SDK and runtime installer.
  • Visual studio 安装程序的版本早于 Visual Studio 2019 版本 16.3。The Visual Studio installer in versions earlier than Visual Studio 2019 version 16.3.

在 macOS 上,该工具只能卸载位于 /usr/local/share/dotnet 文件夹中的 SDK 和运行时。On macOS, the tool can only uninstall SDKs and runtimes located in the /usr/local/share/dotnet folder.

由于这些限制,该工具可能无法卸载计算机上的所有 .NET SDK 和运行时。Because of these limitations, the tool may not be able to uninstall all of the .NET SDKs and runtimes on your machine. 可以使用 dotnet --info 命令来查找所有安装的 .NET SDK 和运行时,包括此工具无法删除的 SDK 和运行时。You can use the dotnet --info command to find all of the .NET SDKs and runtimes installed, including those SDKs and runtimes that this tool can't remove. dotnet-core-uninstall list 命令显示可以通过该工具卸载的 SDK。The dotnet-core-uninstall list command displays which SDKs can be uninstalled with the tool. 版本 1.2 及更高版本可以卸载版本 5.0 或更早版本的 SDK 和运行时,而以前版本的工具可以卸载 3.1 及更早版本。Versions 1.2 and later can uninstall SDKs and runtimes with version 5.0 or earlier, and previous versions of the tool can uninstall 3.1 and earlier.

安装工具Install the tool

可以从工具的发布页面下载 .NET 卸载工具,然后在 dotnet/cli-lab GitHub 存储库中找到源代码。You can download the .NET Uninstall Tool from the tool's releases page and find the source code at the dotnet/cli-lab GitHub repository.

备注

此工具需要提升才能卸载 .NET SDK 和运行时。The tool requires elevation to uninstall .NET SDKs and runtimes. 因此,应将其安装在写入保护的目录中,如 Windows 上的 C:\Program Files 或 macOS 上的 /usr/local/bin。Therefore, it should be installed in a write-protected directory such as C:\Program Files on Windows or /usr/local/bin on macOS. 另请参阅提升的 Dotnet 命令访问权限See also Elevated access for dotnet commands. 有关详细信息,请参阅详细安装说明For more information, see the detailed installation instructions.

运行该工具Run the tool

以下步骤说明了运行卸载工具的建议方法:The following steps show the recommended approach for running the uninstall tool:

步骤 1 - 显示安装的 .NET SDK 和运行时Step 1 - Display installed .NET SDKs and runtimes

dotnet-core-uninstall list 命令列出了已安装的 .NET SDK 和运行时,可以通过此工具将其删除。The dotnet-core-uninstall list command lists the installed .NET SDKs and runtimes that can be removed with this tool. Visual Studio 可能需要某些 SDK 和运行时,它们将显示出来,并说明为何不建议将其卸载。Some SDKs and runtimes may be required by Visual Studio and they're displayed with a note of why it isn't recommended to uninstall them.

备注

在大多数情况下,dotnet-core-uninstall list 命令的输出将与 dotnet --info 输出中的已安装版本列表不匹配。The output of the dotnet-core-uninstall list command will not match the list of installed versions in the output of dotnet --info in most cases. 具体而言,此工具将不会显示通过 zip 文件安装的版本,也不会显示由 Visual Studio(Visual Studio 2019 16.3 或更高版本)托管的版本。Specifically, this tool will not display versions installed by zip files or managed by Visual Studio (any version installed with Visual Studio 2019 16.3 or later). 检查某个版本是否由 Visual Studio 托管的一种方法是在 Add or Remove Programs 中查看该版本,由 Visual Studio 托管的版本在显示名称中会以这种方式标记。One way to check if a version is managed by Visual Studio is to view it in Add or Remove Programs, where Visual Studio managed versions are marked as such in their display names.

dotnet-core-uninstall listdotnet-core-uninstall list

摘要Synopsis

dotnet-core-uninstall list [options]

选项Options

  • --aspnet-runtime

    列出可通过此工具卸载的所有 ASP.NET 运行时。Lists all the ASP.NET Runtimes that can be uninstalled with this tool.

  • --hosting-bundle

    列出可通过此工具卸载的所有 .NET 托管捆绑包。Lists all the .NET hosting bundles that can be uninstalled with this tool.

  • --runtime

    列出可通过此工具卸载的所有 .NET 运行时。Lists all .NET Runtimes that can be uninstalled with this tool.

  • --sdk

    列出可通过此工具卸载的所有 .NET SDK。Lists all .NET SDKs that can be uninstalled with this tool.

  • -v, --verbosity <LEVEL>

    设置详细程度。Sets the verbosity level. 允许使用的值为 q[uiet]m[inimal]n[ormal]d[etailed]diag[nostic]Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]. 默认值为 normalThe default value is normal.

  • --x64

    列出可通过此工具卸载的所有 x64 .NET SDK 和运行时。Lists all x64 .NET SDKs and runtimes that can be uninstalled with this tool.

  • --x86

    列出可通过此工具卸载的所有 x86 .NET SDK 和运行时。Lists all x86 .NET SDKs and runtimes that can be uninstalled with this tool.

示例Examples

  • 列出可通过此工具删除的所有 .NET SDK 和运行时:List all .NET SDKs and runtimes that can be removed with this tool:

    dotnet-core-uninstall list
    
  • 列出所有 x64 .NET SDK 和运行时:List all x64 .NET SDKs and runtimes:

    dotnet-core-uninstall list --x64
    
  • 列出所有 x86 .NET SDK:List all x86 .NET SDKs:

    dotnet-core-uninstall list --sdk --x86
    

步骤 2 - 执行试运行Step 2 - Do a dry run

dotnet-core-uninstall dry-rundotnet-core-uninstall whatif 命令显示将根据提供的选项删除的 .NET SDK 和运行时,而无需执行卸载。The dotnet-core-uninstall dry-run and dotnet-core-uninstall whatif commands display the .NET SDKs and runtimes that will be removed based on the options provided without performing the uninstall. 这些命令是同义词。These commands are synonyms.

dotnet-core-uninstall dry-run 和 dotnet-core-uninstall whatifdotnet-core-uninstall dry-run and dotnet-core-uninstall whatif

摘要Synopsis

dotnet-core-uninstall dry-run [options] [<VERSION>...]

dotnet-core-uninstall whatif [options] [<VERSION>...]

自变量Arguments

  • VERSION

    要卸载的指定版本。The specified version to uninstall. 可以逐一列出多个版本,用空格分隔。You may list several versions one after the other, separated by spaces. 此外还支持响应文件。Response files are also supported.

    提示

    响应文件是在命令行上放置所有版本的替代方法。Response files are an alternative to placing all the versions on the command line. 它们是文本文件,通常具有 *.rsp 扩展名,每个版本都在单独的行上列出。They're text files, typically with a *.rsp extension, and each version is listed on a separate line. 若要为 VERSION 参数指定响应文件,请使用后面紧跟响应文件名的 @ 字符。To specify a response file for the VERSION argument, use the @ character immediately followed by the response file name.

选项Options

  • --all

    删除所有 .NET SDK 和运行时。Removes all .NET SDKs and runtimes.

  • --all-below <VERSION>[ <VERSION>...]

    仅删除版本小于指定版本的 .NET SDK 和运行时。Removes only the .NET SDKs and runtimes with a version smaller than the specified version. 仍安装指定版本。The specified version remains installed.

  • --all-but <VERSIONS>[ <VERSION>...]

    除了那些指定版本外,删除所有 .NET SDK 和运行时。Removes all .NET SDKs and runtimes, except those versions specified.

  • --all-but-latest

    删除 .NET SDK 和运行时(最高版本除外)。Removes .NET SDKs and runtimes, except the one highest version.

  • --all-lower-patches

    删除由较高版本的修补程序取代的 .NET SDK 和运行时。Removes .NET SDKs and runtimes superseded by higher patches. 此选项保护 global.json。This option protects global.json.

  • --all-previews

    删除标记为预览的 .NET SDK 和运行时。Removes .NET SDKs and runtimes marked as previews.

  • --all-previews-but-latest

    删除标记为预览的 .NET SDK 和运行时(最高预览版除外)。Removes .NET SDKs and runtimes marked as previews except the one highest preview.

  • --aspnet-runtime

    仅删除 ASP.NET 运行时。Removes ASP.NET Runtimes only.

  • --hosting-bundle

    仅删除 .NET 运行时和托管绑定。Removes .NET Runtime and hosting bundles only.

  • --major-minor <MAJOR_MINOR>

    删除与指定 major.minor 版本相匹配的 .NET SDK 和运行时。Removes .NET SDKs and runtimes that match the specified major.minor version.

  • --runtime

    仅删除 .NET 运行时。Removes .NET Runtimes only.

  • --sdk

    仅删除 .NET SDK。Removes .NET SDKs only.

  • -v, --verbosity <LEVEL>

    设置详细程度。Sets the verbosity level. 允许使用的值为 q[uiet]m[inimal]n[ormal]d[etailed]diag[nostic]Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]. 默认值为 normalThe default value is normal.

  • --x64

    必须与 --sdk--runtime--aspnet-runtime 结合使用才能删除 x64 SDK 或运行时。Must be used with --sdk, --runtime, and --aspnet-runtime to remove x64 SDKs or runtimes.

  • --x86

    必须与 --sdk--runtime--aspnet-runtime 结合使用才能删除 x86 SDK 或运行时。Must be used with --sdk, --runtime, and --aspnet-runtime to remove x86 SDKs or runtimes.

  • --force 强制删除可能由 Visual Studio 使用的版本。--force Forces removal of versions that might be used by Visual Studio.

注意:Notes:

  1. 只需 --sdk--runtime--aspnet-runtime--hosting-bundle 中的一个。Exactly one of --sdk, --runtime, --aspnet-runtime, and --hosting-bundle is required.
  2. --all--all-below--all-but--all-but-latest--all-lower-patches--all-previews--all-previews-but-latest--major-minor[<VERSION>...] 除外。--all, --all-below, --all-but, --all-but-latest, --all-lower-patches, --all-previews, --all-previews-but-latest, --major-minor, and [<VERSION>...] are exclusive.
  3. 如果未指定 --x64--x86,则同时删除 x64 和 x86。If --x64 or --x86 aren't specified, then both x64 and x86 will be removed.

示例Examples

备注

默认情况下,Visual Studio 或其他 SDK 可能需要的 .NET SDK 和运行时不会包含在 dotnet-core-uninstall dry-run 输出中。By default, .NET SDKs and runtimes that may be required by Visual Studio or other SDKs are not included in dotnet-core-uninstall dry-run output. 在下面的示例中,某些指定的 SDK 和运行时可能不会包含在输出中,具体取决于计算机的状态。In the following examples, some of the specified SDKs and runtimes may not be included in the output, depending on the state of the machine. 若要包括所有 SDK 和运行时,请将它们显式列出为参数或使用 --force 选项。To include all SDKs and runtimes, list them explicitly as arguments or use the --force option.

  • 试运行删除已被较高版本的修补程序取代的所有 .NET 运行时:Dry run of removing all .NET Runtimes that have been superseded by higher patches:

    dotnet-core-uninstall dry-run --all-lower-patches --runtime
    
  • 试运行删除低于版本 2.2.301 的所有 .NET SDK:Dry run of removing all .NET SDKs below the version 2.2.301:

    dotnet-core-uninstall whatif --all-below 2.2.301 --sdk
    

步骤 3 - 卸载 .NET SDK 和运行时Step 3 - Uninstall .NET SDKs and Runtimes

dotnet-core-uninstall remove 卸载由选项集合指定的 .NET SDK 和运行时。dotnet-core-uninstall remove uninstalls .NET SDKs and Runtimes that are specified by a collection of options. 版本 1.2 及更高版本可以卸载版本 5.0 或更早版本的 SDK 和运行时,而以前版本的工具可以卸载 3.1 及更早版本。Versions 1.2 and later can uninstall SDKs and runtimes with version 5.0 or earlier, and previous versions of the tool can uninstall 3.1 and earlier.

由于此工具具有破坏性行为,因此强烈建议在运行 remove 命令之前执行试运行。Since this tool has a destructive behavior, it's highly recommended that you do a dry run before running the remove command. 使用 remove 命令时,试运行将显示要删除的 .NET SDK 和运行时。The dry run will show you what .NET SDKs and runtimes will be removed when you use the remove command. 请参阅是否应删除版本?了解哪些 SDK 和运行时可以安全删除。Refer to Should I remove a version? to learn which SDKs and runtimes are safe to remove.

注意

请记住以下注意事项:Keep in mind the following caveats:

  • 此工具可以卸载计算机上 global.json 文件所需的 .NET SDK 版本。This tool can uninstall versions of the .NET SDK that are required by global.json files on your machine. 可以从下载 .NET 页重新安装 .NET SDK。You can reinstall .NET SDKs from the Download .NET page.
  • 此工具可以卸载计算机上依赖于框架的应用程序所需的 .NET 运行时版本。This tool can uninstall versions of the .NET Runtime that are required by framework dependent applications on your machine. 可以从下载 .NET 页重新安装 .NET 运行时。You can reinstall .NET Runtimes from the Download .NET page.
  • 此工具可以卸载 Visual Studio 所依赖的 .NET SDK 和运行时版本。This tool can uninstall versions of the .NET SDK and runtime that Visual Studio relies on. 如果中断 Visual Studio 安装,请在 Visual Studio 安装程序中运行“修复”以返回到工作状态。If you break your Visual Studio installation, run "Repair" in the Visual Studio installer to get back to a working state.

默认情况下,所有命令都将保留 Visual Studio 或其他 SDK 可能需要的 .NET SDK 和运行时。By default, all commands keep the .NET SDKs and runtimes that may be required by Visual Studio or other SDKs. 可以通过将这些 SDK 和运行时显式列出为参数或使用 --force 选项来卸载这些 SDK 和运行时。These SDKs and runtimes can be uninstalled by listing them explicitly as arguments or by using the --force option.

此工具需要提升才能卸载 .NET SDK 和运行时。The tool requires elevation to uninstall .NET SDKs and runtimes. 在 Windows 上的管理员命令提示符中运行此工具,在 macOS 上则通过 sudo 运行。Run the tool in an Administrator command prompt on Windows and with sudo on macOS. dry-runwhatif 命令不需要提升。The dry-run and whatif commands don't require elevation.

dotnet-core-uninstall removedotnet-core-uninstall remove

摘要Synopsis

dotnet-core-uninstall remove [options] [<VERSION>...]

自变量Arguments

  • VERSION

    要卸载的指定版本。The specified version to uninstall. 可以逐一列出多个版本,用空格分隔。You may list several versions one after the other, separated by spaces. 此外还支持响应文件。Response files are also supported.

    提示

    响应文件是在命令行上放置所有版本的替代方法。Response files are an alternative to placing all the versions on the command line. 它们是文本文件,通常具有 *.rsp 扩展名,每个版本都在单独的行上列出。They're text files, typically with a *.rsp extension, and each version is listed on a separate line. 若要为 VERSION 参数指定响应文件,请使用后面紧跟响应文件名的 @ 字符。To specify a response file for the VERSION argument, use the @ character immediately followed by the response file name.

选项Options

  • --all

    删除所有 .NET SDK 和运行时。Removes all .NET SDKs and runtimes.

  • --all-below <VERSION>[ <VERSION>...]

    仅删除版本小于指定版本的 .NET SDK 和运行时。Removes only the .NET SDKs and runtimes with a version smaller than the specified version. 仍安装指定版本。The specified version remains installed.

  • --all-but <VERSIONS>[ <VERSION>...]

    除了那些指定版本外,删除所有 .NET SDK 和运行时。Removes all .NET SDKs and runtimes, except those versions specified.

  • --all-but-latest

    删除 .NET SDK 和运行时(最高版本除外)。Removes .NET SDKs and runtimes, except the one highest version.

  • --all-lower-patches

    删除由较高版本的修补程序取代的 .NET SDK 和运行时。Removes .NET SDKs and runtimes superseded by higher patches. 此选项保护 global.json。This option protects global.json.

  • --all-previews

    删除标记为预览的 .NET SDK 和运行时。Removes .NET SDKs and runtimes marked as previews.

  • --all-previews-but-latest

    删除标记为预览的 .NET SDK 和运行时(最高预览版除外)。Removes .NET SDKs and runtimes marked as previews except the one highest preview.

  • --aspnet-runtime

    仅删除 ASP.NET 运行时。Removes ASP.NET Runtimes only.

  • --hosting-bundle

    仅删除 .NET 托管绑定。Removes .NET hosting bundles only.

  • --major-minor <MAJOR_MINOR>

    删除与指定 major.minor 版本相匹配的 .NET SDK 和运行时。Removes .NET SDKs and runtimes that match the specified major.minor version.

  • --runtime

    仅删除 .NET 运行时。Removes .NET Runtimes only.

  • --sdk

    仅删除 .NET SDK。Removes .NET SDKs only.

  • -v, --verbosity <LEVEL>

    设置详细程度。Sets the verbosity level. 允许使用的值为 q[uiet]m[inimal]n[ormal]d[etailed]diag[nostic]Allowed values are q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]. 默认值为 normalThe default value is normal.

  • --x64

    必须与 --sdk--runtime--aspnet-runtime 结合使用才能删除 x64 SDK 或运行时。Must be used with --sdk, --runtime, and --aspnet-runtime to remove x64 SDKs or runtimes.

  • --x86

    必须与 --sdk--runtime--aspnet-runtime 结合使用才能删除 x86 SDK 或运行时。Must be used with --sdk, --runtime, and --aspnet-runtime to remove x86 SDKs or runtimes.

  • -y, --yes 执行命令而不需要进行是或否确认。-y, --yes Executes the command without requiring a yes or no confirmation.

  • --force 强制删除可能由 Visual Studio 使用的版本。--force Forces removal of versions that might be used by Visual Studio.

注意:Notes:

  1. 只需 --sdk--runtime--aspnet-runtime--hosting-bundle 中的一个。Exactly one of --sdk, --runtime, --aspnet-runtime, and --hosting-bundle is required.
  2. --all--all-below--all-but--all-but-latest--all-lower-patches--all-previews--all-previews-but-latest--major-minor[<VERSION>...] 除外。--all, --all-below, --all-but, --all-but-latest, --all-lower-patches, --all-previews, --all-previews-but-latest, --major-minor, and [<VERSION>...] are exclusive.
  3. 如果未指定 --x64--x86,则同时删除 x64 和 x86。If --x64 or --x86 aren't specified, then both x64 and x86 will be removed.

示例Examples

备注

默认情况下,将保留 Visual Studio 或其他 SDK 可能需要的 .NET SDK 和运行时。By default, .NET SDKs and runtimes that may be required by Visual Studio or other SDKs are kept. 在下面的示例中,可能保留某些指定的 SDK 和运行时,具体取决于计算机的状态。In the following examples, some of the specified SDKs and runtimes may remain, depending on the state of the machine. 若要删除所有 SDK 和运行时,请将它们显式列出为参数或使用 --force 选项。To remove all SDKs and runtimes, list them explicitly as arguments or use the --force option.

  • 删除除版本 3.0.0-preview6-27804-01 之外的所有 .NET 运行时,无需进行 Y/N 确认:Remove all .NET Runtimes except the version 3.0.0-preview6-27804-01 without requiring Y/N confirmation:

    dotnet-core-uninstall remove --all-but 3.0.0-preview6-27804-01 --runtime --yes
    
  • 删除所有 .NET Core 1.1 SDK,无需进行 Y/N 确认:Remove all .NET Core 1.1 SDKs without requiring Y/n confirmation:

    dotnet-core-uninstall remove --sdk --major-minor 1.1 -y
    
  • 删除没有控制台输出的 .NET Core 1.1.11 SDK:Remove the .NET Core 1.1.11 SDK with no console output:

    dotnet-core-uninstall remove 1.1.11 --sdk --yes --verbosity q
    
  • 删除可由此工具安全删除的所有 .NET SDK:Remove all .NET SDKs that can safely be removed by this tool:

    dotnet-core-uninstall remove --all --sdk
    
  • 删除此工具可删除的所有 .NET SDK,包括 Visual Studio 可能需要的 SDK(不推荐):Remove all .NET SDKs that can be removed by this tool, including those SDKs that may be required by Visual Studio (not recommended):

    dotnet-core-uninstall remove --all --sdk --force
    
  • 删除响应文件 versions.rsp 中指定的所有 .NET SDKRemove all .NET SDKs that are specified in the response file versions.rsp

    dotnet-core-uninstall remove --sdk @versions.rsp
    

    versions.rsp 的内容如下所示:The content of versions.rsp is as follows:

    2.2.300
    2.1.700
    

步骤 4 - 删除 NuGet 回退文件夹(可选)Step 4 - Delete the NuGet fallback folder (optional)

在某些情况下,你不再需要 NuGetFallbackFolder,可能希望将其删除。In some cases, you no longer need the NuGetFallbackFolder and may wish to delete it. 有关删除此文件夹的详细信息,请参阅删除 NuGetFallbackFolderFor more information about deleting this folder, see Remove the NuGetFallbackFolder.

卸载工具Uninstall the tool

  1. 打开“添加或删除程序”。Open Add or Remove Programs.
  2. 搜索 Microsoft .NET SDK Uninstall ToolSearch for Microsoft .NET SDK Uninstall Tool.
  3. 选择“卸载”。Select Uninstall.