Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a dotnet runtime on Windows?

I've found the command dotnet --list-runtimes and it outputs (abbreviated) for me:

Microsoft.AspNetCore.All 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.15 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.2.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 3.1.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

I want to remove specific AspNetCore.App runtimes to see if it helps me solve another, different issue - but I don't know how.

I've tried:

  • Using Add/Remove Programs, but it only lists ".NET Core SDK" entries, not runtimes (also: this list is missing several versions that were in the dotnet --list-runtimes output)
  • Going through the available dotnet help entries, but saw no relevant option
  • Go through the remove-runtime-sdk-version readme but it tells me to use Add/Remove Programs, which doesn't help me

I've considered removing the folders mentioned in my output, but am hesitant to just start deleting folders in Program Files subfolders.

Is there a dotnet command or other good way to remove runtimes, specifically AspNetCore versions, so that I can be 100% sure that the "Version Selection" feature from ASP.NET Core cannot pick up a wrong version?


Per the comments, I've tried the dotnet-core-uninstall tool (preview release), but if I run dotnet-core-uninstall it lists zero runtimes it could uninstall, only SDKs (and only 2.x versions at that).

like image 269
Jeroen Avatar asked Sep 08 '25 18:09

Jeroen


1 Answers

For the older Versions of .Net, the tool dotnet-core-uninstall does not work. In my case, I had for example Microsoft.NETCore.App 3.1.23 (Maybe from an old Visual Studio 2019 installation?).

Here is what I did to get rid of it:

  1. I opened a console with admin rights
  2. I listed all the .Net runtimes by running 'dotnet --list-runtimes'
  3. I opened the folder 'C:\Windows\Installer'

This folder is sometimes invisible, but its definitely there. In this folder I enabled the column 'Subject' that shows the content of the installer. The installers themselfs only have a cryptic filename like b23f58.msi. I picked the right installer for my Version of .Net runtime (The Version is also shown in the 'Subject' column).

  1. I copied the msi-installer to C:\Temp (This might be unnesessary)
  2. I ran the installer from the console with admin rights an then klicked on 'Remove' when the option came up

And the runtime was gone.

Finding the right Installer can be a bit fiddely, because the names are not always the same as in the output of 'dotnet --info'. Just try until you hit the right one. As long as it has the old version number that you want to get rid of, you should be save.

ALternative way to find the installer: run

REG QUERY HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall /f ".NET CORE" /s

on the console to show Versions of .Net Core

Then go to 'C:\ProgramData\Package Cache' and list the directories. They all start with a very long hex number with corresponds to the hex number from the command above. Go to the directory with the right hex number and find inside a msi-installer. Or just search in 'C:\ProgramData\Package Cache' for the Version number or 'NETCore' and see what you find.

Then proceed like above with the installer.

As my forst approach worked for me, so I haven't tried this myself.

like image 68
Michael W. Avatar answered Sep 10 '25 06:09

Michael W.