Scott Hanselman

Scripts to remove old .NET Core SDKs

September 20, '18 Comments [10] Posted in DotNetCore
Sponsored By

That's a lot of .NET Core installations.NET Core is lovely. Its usage is skyrocketing, it's open source, and .NET Core 2.1 has some amazing performance improvements. Just upgrading from 2.0 to 2.1 gave Bing a 34% performance boost.

However, for those of us who are installing multiple .NET Core SDKs side by side have noticed that they add-up if you are installing daily builds or very often. As of 2.x, .NET Core doesn't yet have an "uninstall all" or "uninstall all previews" option. There will be work done in .NET Core 3.0 that will mitigate this cumulative effect when you have lots of installers.

If you're taking dailies and it's time to tidy up, the short answer per Damian Edwards is "Delete them all, then nuke the dotnet folder in program files, then install the latest version."

Here's a PowerShell Script you can run on Windows as admin that will aggressively uninstall .NET Core SDKs.

Note the match at the top. Depending on your goals, you might want to change it to "Microsoft .NET Core SDK 2.1" or just "Microsoft .NET Core SDK 2."

Once it's all removed, then add the latest from https://www.microsoft.com/net/download/archives

A list of .NET Core SDKs

Here's the script, which is an improvement on Andrew's comment here. You can improve it as it's on GitHub here https://github.com/shanselman/RemoveDotNetCoreSDKInstallers. This scripts currently requires you to hit YES as the MSIs elevate. It doesn't work right then you try /passive as a switch. I'm interesting if you can get a "torch all Core SDK installers and install LTS and Current" script working.

$app = Get-WmiObject -Class Win32_Product | Where-Object { 
    $_.Name -match "Microsoft .NET Core SDK" 
}

Write-Host $app.Name 
Write-Host $app.IdentifyingNumber
pushd $env:SYSTEMROOT\System32

$app.identifyingnumber |% { Start-Process msiexec -wait -ArgumentList "/x $_" }

popd

This PowerShell is Windows-only, of course.

If you're on RHEL, Ubuntu/Debian, there are scripts here to try out https://github.com/dotnet/cli/tree/master/scripts/obtain/uninstall

Let me know if this script works for you.


Sponsor: Copy: Rider 2018.2 is here! Publishing to IIS, Docker support in the debugger, built-in spell checking, MacBook Touch Bar support, full C# 7.3 support, advanced Unity support, and more.

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Sponsored By
Hosting By
Dedicated Windows Server Hosting by SherWeb
Monday, 24 September 2018 06:49:29 UTC
I tested it and when I see the "Add remove programs" of Windows, nothing has changed and nothing is uninstalled.
Saeid
Monday, 24 September 2018 06:54:28 UTC
You might want to be careful using win32_product on a server. It causes all msi packages on the system to run a repair. Shouldn't be a problem on your local dev box but keep it in mind.
Wil
Monday, 24 September 2018 06:57:33 UTC
Also it doesn't see the ".NET Core 1.0.0 - sdk"'s. There's a version number here in between.
Saeid
Monday, 24 September 2018 07:37:34 UTC
I started writing a global tool to do this at the Summit hackathon last year and just never got it published, maybe time to revisit that :)
Monday, 24 September 2018 08:27:24 UTC
I can easily add a "One elevation to rule them all" code to this PowerShell script, if anyone's interested.
Fleet Command
Monday, 24 September 2018 13:30:09 UTC
Tread lightly while uninstalling .NET Core SDKs. Over a week ago attempt at doing just that on my machine rendered VS 2017 installation completely dead - couldn't install the updates. Uninstall didn't work either. Manually removed it and could no longer install it either. MS support ticket is still open for over a week now with no end in sight. So, machine's been re-imaged. You've been warned.
Sergey M
Wednesday, 26 September 2018 06:34:20 UTC
Thanks for sharing its very useful for me.
How can I uninstall dotnet core from macOS Sierra.
Friday, 28 September 2018 17:50:45 UTC
When you click on one of those installed SDKs, it will show you the version. For previews, it should show 4 part version (e.g. 2.1.300.8866 for .Net Core SDK 2.1.300 "RTM"). For non-previews, it will show only 3 parts (e.g. 2.1.300).
Tuesday, 02 October 2018 04:06:32 UTC
Thanks, its work on my windows computer.

Tubi TV Activate
Wednesday, 03 October 2018 10:46:02 UTC
Thanks Scott. Good one to remove old .net core sdks from application.
Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.