.NET Core の SDK がいっぱいインストールされてて大変だよぉ…を解決


.NET Core は、結構頻繁にアップデートされていて、いつの間にか(Visual Studio をアップデートしたりしてるうちに)プログラムの一覧がこのような有様になります。
(これでも定期的にチェックしていらないやつは消してるのに…)

.NET Core SDK は 1 つあたり 500 MB くらいあるので、2 ついらないものが入ってるだけで 1 GB 持っていかれます。ありがとうございます。
ということで、ぽちぽち消していたのですが、先日 .NET Core アンインストール ツールというものが公開されていました。

.NET Core アンインストール ツール

入れてみて Windows Terminal で dotnet-core-uninstall list を打ってみると以下のように表示されました。

> dotnet-core-uninstall list

This tool can not 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:
  3.1.102  x64    [Used by Visual Studio. Specify individually or use ?-force to remove]
  2.2.402  x64    [Used by Visual Studio 2019. Specify individually or use ?-force to remove]
  2.2.401  x64
  2.1.802  x64    [Used by Visual Studio 2019. Specify individually or use ?-force to remove]
  2.1.801  x64

.NET Core Runtimes:

ASP.NET Core Runtimes:

.NET Core Runtime & Hosting Bundles:

ふむふむ、SDK を 2 つくらい消しても大丈夫そうだなぁということで消します! 1 GB の空き領域ゲットだぜ。

ということでいらない SDK を消す前に、どれがコマンドで消されるのかをチェックする dry-run を行います。dotnet-core-uninstall dry-run --all --sdk を実行すると以下のような結果になりました。

> dotnet-core-uninstall dry-run --all --sdk
*** DRY RUN OUTPUT
Specified versions:
  Microsoft .NET Core SDK 2.2.401 (x64)
  Microsoft .NET Core SDK 2.1.801 (x64)
*** END DRY RUN OUTPUT

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

Run as administrator and use the remove command to uninstall these items.

dry-run で確認したので次は remove で消します。管理者権限で起動した Windows Terminal で dotnet-core-uninstall remove --all --sdk を実行します。

実行すると以下のような結果になりました。ちゃんと本当に消す前に聞いてくれます。

> dotnet-core-uninstall remove --all --sdk
The following items will be removed:
  Microsoft .NET Core SDK 2.2.401 (x64)
  Microsoft .NET Core SDK 2.1.801 (x64)

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

Do you want to continue? [Y/n] Y
Uninstalling: Microsoft .NET Core SDK 2.2.401 (x64).
Uninstalling: Microsoft .NET Core SDK 2.1.801 (x64).
消す前

消した後

空き領域がちゃんと 1 GB 増えました。やったね。

まとめ

これからは、手動で 1 つ 1 つ心を込めて消す必要がなくなって、心に余裕が生まれそうです。