移除 dotnet SDK 和 Runtime

筆者今天在 GitHub 上四處亂逛,尋找今天文章的靈感時,意外的發現了一個很特別的儲存庫:dotnet/cli-lab

這個是微軟專門存放 .NET 相關的 GitHub 組織,這個儲存庫名稱會讓人聯想到指令介面(CLI, Command Line Interface)實驗室(Laboratory),但是裡面確說明這個儲存庫是 .NET 的解除安裝工具,不知道未來這個儲存庫會不會改名。

以前的 .NET Core 移除工具是一個 .NET Core 全域工具,也因此會使用到已安裝的 .NET 執行環境(Runtime),但是使用者有可能不知道這個工具目前到底是使用哪個版本,可能會想要移除掉該工具目前使用的執行環境版本而發生錯誤,所以才會改成現在這樣需要手動安裝的工具。



首先先到 GitHub 專案儲存庫的發佈頁面,下載最新的版本,如果是 Windows 就下載 .msi 的檔案,然後執行檔案、依照步驟安裝。

安裝完畢後使用系統管理員權限開啟指令視窗,使用指令來移除。

列出可以使用 dotnet-core-uninstal 工具移除的清單,包含 Runtime, SDK 等:
    
dotnet-core-uninstall list
    

範例輸出:
    
dotnet-core-uninstall list

This tool cannot uninstall versions of the runtime or SDK that are?
    - SDKs installed using Visual Studio 2019 Update 3 or later.
    - SDKs and runtimes installed via zip/scripts.
    - Runtimes installed with SDKs (these should be removed by removing that SDK).
The versions that can be uninstalled with this tool are:

.NET Core SDKs:
  9.0.103  x64    [Used by Visual Studio. Specify individually or use —-force to remove]
  8.0.206  x64    [Used by Visual Studio 2022. Specify individually or use —-force to remove]
  8.0.113  x64
  7.0.410  x64    [Used by Visual Studio 2022. Specify individually or use —-force to remove]
  7.0.317  x64
  6.0.428  x64    [Used by Visual Studio 2022. Specify individually or use —-force to remove]

.NET Core Runtimes:
  6.0.36  x64

ASP.NET Core Runtimes:

.NET Core Runtime & Hosting Bundles:
    

移除時需要指定要移除的類型,有以下參數可以選擇:
  • --aspnet-runtime
  • --hosting-bundle
  • --runtime
  • --sdk
假設要移除 6.0.36 版本的 Runtime ,則指令為:
    
dotnet-core-uninstall remove 6.0.36 --runtime
    

範例輸出:
    
dotnet-core-uninstall remove 6.0.36 --runtime
The following items will be removed:
  Microsoft .NET Runtime - 6.0.36 (x64)

To avoid breaking Visual Studio or other problems, read https://aka.ms/dotnet-core-uninstall-docs.

Do you want to continue? [y/n] y
Uninstalling: Microsoft .NET Runtime - 6.0.36 (x64).
    



參考資料:
Microsoft.Learn - .NET uninstall tool overview
GitHub - dotnet/cli-lab

留言