如何移除 .NET Core 執行階段和 SDKHow to remove the .NET Core Runtime and SDK

隨時間下來,當您安裝 .NET Core 執行階段和 SDK 的更新版本時,您可能想要從電腦移除過期的 .NET Core 版本。Over time, as you install updated versions of the .NET Core runtime and SDK, you may want to remove outdated versions of .NET Core from your machine. 移除舊版執行階段可能會變更選為執行共用架構應用程式的執行階段,如 .NET Core 版本選取一文所述。Removing older versions of the runtime may change the runtime chosen to run shared framework applications, as detailed in the article on .NET Core version selection.

我是否應該移除某個版本?Should I remove a version?

.NET Core 版本選取行為及不同更新之間的 .NET Core 執行階段相容性,可讓您安全地移除舊版。The .NET Core version selection behaviors and the runtime compatibility of .NET Core across updates enables safe removal of previous versions. .NET Core 執行階段更新在主要版本「範圍」內 (例如 1.x 和 2.x) 是相容的。.NET Core runtime updates are compatible within a major version 'band' such as 1.x and 2.x. 此外,較新版本的 .NET Core SDK 通常能夠繼續以相容的方式,來建置以舊版執行階段為目標的應用程式。Additionally, newer releases of the .NET Core SDK generally maintain the ability to build applications that target previous versions of the runtime in a compatible manner.

一般而言,您只需要最新的 SDK,以及您應用程式所需之執行階段的最新修補版本。In general, you only need the latest SDK and latest patch version of the runtimes required for your application. 保留較舊的 SDK 或執行階段版本的實例包括維護基於project.json的應用程式。Instances where keeping older SDK or Runtime versions include maintaining project.json-based applications. 除非您的應用程式有特定理由需要舊版 SDK 或執行階段,否則您可以安全地移除舊版。Unless your application has specific reasons for earlier SDKs or runtimes, you may safely remove older versions.

判斷已安裝的項目Determine what is installed

從 .NET Core 2.1 開始,.NET CLI 可讓您選擇使用電腦上安裝的 SDK 和執行階段版本清單。Starting with .NET Core 2.1, the .NET CLI has options you can use to list the versions of the SDK and runtime that are installed on your machine. 用於dotnet --list-sdks查看電腦上安裝的 SDK 清單。Use dotnet --list-sdks to see the list of SDKs installed on your machine. 用於dotnet --list-runtimes查看電腦上安裝的運行時清單。Use dotnet --list-runtimes to see the list of runtimes installed on your machine. 下列文字顯示 Windows、macOS 或 Linux 的一般輸出:The following text shows typical output for Windows, macOS, or Linux:

通過運行以下命令:By running the following command:

dotnet --list-sdks

您將獲得類似于以下內容的輸出:You get output similar to the following:

2.1.200-preview-007474 [C:\Program Files\dotnet\sdk]
2.1.200-preview-007480 [C:\Program Files\dotnet\sdk]
2.1.200-preview-007509 [C:\Program Files\dotnet\sdk]
2.1.200-preview-007570 [C:\Program Files\dotnet\sdk]
2.1.200-preview-007576 [C:\Program Files\dotnet\sdk]
2.1.200-preview-007587 [C:\Program Files\dotnet\sdk]
2.1.200-preview-007589 [C:\Program Files\dotnet\sdk]
2.1.200 [C:\Program Files\dotnet\sdk]
2.1.201 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.300-preview2-008533 [C:\Program Files\dotnet\sdk]
2.1.300 [C:\Program Files\dotnet\sdk]
2.1.400-preview-009063 [C:\Program Files\dotnet\sdk]
2.1.400-preview-009088 [C:\Program Files\dotnet\sdk]
2.1.400-preview-009171 [C:\Program Files\dotnet\sdk]

通過運行以下命令:And by running the following command:

dotnet --list-runtimes

您將獲得類似于以下內容的輸出:You get output similar to the following:

Microsoft.AspNetCore.All 2.1.0-preview2-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.0-preview2-final [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.0-preview2-26406-04 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

卸載 .NET 核心Uninstall .NET Core

.NET Core 使用 Windows [新增/移除程式]**** 對話方塊來移除 .NET Core 執行階段和 SDK 版本。.NET Core uses the Windows Add/Remove Programs dialog to remove versions of the .NET Core runtime and SDK. 下圖顯示 [新增/移除程式]**** 對話方塊,其中已安裝數個 .NET 執行階段和 SDK 版本。The following figure shows the Add/Remove Programs dialog with several versions of the .NET runtime and SDK installed.

用以移除 .NET Core 的 [新增/移除程式]

選取您想要從電腦移除的任意版本,然後按一下 [解除安裝]****。Select any versions you want to remove from your machine and click Uninstall.

.NET Core 解除安裝工具.NET Core Uninstall Tool

.NET 核心卸載工具dotnet-core-uninstall) 允許您從系統中刪除 .NET 核心 SDK 和運行時。The .NET Core Uninstall Tool (dotnet-core-uninstall) lets you remove .NET Core SDKs and runtimes from a system. 選項組合可用於指定應卸載哪些版本。A collection of options is available to specify which versions should be uninstalled.

對 .NET 核心 SDK 版本的視覺化工作室依賴Visual Studio dependency on .NET Core SDK versions

在 Visual Studio 2019 版本 16.3 之前,Visual Studio 安裝程式稱為獨立的 .NET 酷睿 SDK 安裝程式。Before Visual Studio 2019 version 16.3, Visual Studio installers called the standalone .NET Core SDK installer. 因此,SDK 版本將顯示在 Windows添加/刪除程式對話方塊中。As a result, the SDK versions appear in the Windows Add/Remove Programs dialog. 刪除 Visual Studio 使用獨立安裝程式安裝的 .NET 核心 SDK 可能會中斷 Visual Studio。Removing .NET Core SDKs that were installed by Visual Studio using the standalone installer may break Visual Studio. 如果卸載 SDK 後 Visual Studio 出現問題,請對該特定版本的 Visual Studio 運行修復。If Visual Studio has problems after you uninstall SDKs, run Repair on that specific version of Visual Studio. 下表顯示了 .NET Core SDK 版本的一些 Visual Studio 依賴項:The following table shows some of the Visual Studio dependencies on .NET Core SDK versions:

Visual Studio 版本Visual Studio version .NET 核心 SDK 版本.NET Core SDK version
Visual Studio 2019 16.2 版Visual Studio 2019 version 16.2 .NET 核心 SDK 2.2.4xx, 2.1.8xx.NET Core SDK 2.2.4xx, 2.1.8xx
Visual Studio 2019 16.1 版Visual Studio 2019 version 16.1 .NET 核心 SDK 2.2.3xx, 2.1.7xx.NET Core SDK 2.2.3xx, 2.1.7xx
視覺工作室 2019 版本 16.0Visual Studio 2019 version 16.0 .NET 核心 SDK 2.2.2xx, 2.1.6xx.NET Core SDK 2.2.2xx, 2.1.6xx
視覺工作室 2017 版本 15.9Visual Studio 2017 version 15.9 .NET 核心 SDK 2.2.1xx, 2.1.5xx.NET Core SDK 2.2.1xx, 2.1.5xx
Visual Studio 2017 15.8 版Visual Studio 2017 version 15.8 .NET 核心 SDK 2.1.4xx.NET Core SDK 2.1.4xx

從 Visual Studio 2019 版本 16.3 開始,Visual Studio 負責自己的 .NET 核心 SDK 副本。Starting with Visual Studio 2019 version 16.3, Visual Studio is in charge of its own copy of the .NET Core SDK. 因此,您不再在 "添加/刪除程式" 對話方塊中看到這些 SDK 版本。For that reason, you no longer see those SDK versions in the Add/Remove Programs dialog.

刪除 NuGet 回退資料夾Remove the NuGet fallback folder

在 .NET Core 3.0 SDK 之前,.NET Core SDK 安裝程式使用NuGetFallbackFolder存儲 NuGet 包的緩存。Before .NET Core 3.0 SDK, the .NET Core SDK installers used the NuGetFallbackFolder to store a cache of NuGet packages. 此緩存在操作(如dotnet restoredotnet build /t:Restore) 時使用。This cache was used during operations such as dotnet restore or dotnet build /t:Restore. 位於NuGetFallbackFolderWindows 上的*C:*程式檔\dotnet_sdk,* 位於 macOS 上的 /usr/local/share/點網/sdk。The NuGetFallbackFolder is located at C:\Program Files\dotnet\sdk on Windows and at /usr/local/share/dotnet/sdk on macOS.

您可能希望刪除此資料夾,如果:You may want to remove this folder, if:

  • 您只使用 .NET Core 3.0 SDK 或更高版本進行開發。You're only developing using .NET Core 3.0 SDK or later versions.
  • 您正在使用早于 3.0 的 .NET Core SDK 版本進行開發,但您可以連線工作,並且速度可能會變慢一次。You're developing using .NET Core SDK versions earlier than 3.0, but you can work online and things can be slower once.

如果要刪除 NuGet 回退資料夾,可以將其刪除,但需要管理員許可權才能刪除。If you want to remove the NuGet fallback folder, you can delete it, but you'll need admin privileges to do so.

不建議刪除dotnet資料夾。It's not recommended to delete the dotnet folder. 這樣做將刪除以前安裝的任何全域工具。Doing so would remove any global tools you've previously installed. 此外,在 Windows 上:Also, on Windows:

  • 您將打破 Visual Studio 2019 版本 16.3 和更高版本。You'll break Visual Studio 2019 version 16.3 and later versions. 您可以運行 "修復" 以恢復。You can run Repair to recover.
  • 如果在 "添加/刪除程式" 對話方塊中有 .NET 核心 SDK 條目,則這些條目將孤立化。If there are .NET Core SDK entries in the Add/Remove Programs dialog, they'll be orphaned.