question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to remove old .NET Core SDKs?

See original GitHub issue

After installing .NET Core 2.1 SDK (great job, BTW), dotnet --info showed me I had all this installed:

.NET Core SDKs installed:
  2.1.4 [C:\Program Files\dotnet\sdk]
  2.1.100-preview-007328 [C:\Program Files\dotnet\sdk]
  2.1.100-preview-007341 [C:\Program Files\dotnet\sdk]
  2.1.100-preview-007354 [C:\Program Files\dotnet\sdk]
  2.1.100-preview-007363 [C:\Program Files\dotnet\sdk]
  2.1.100-preview-007391 [C:\Program Files\dotnet\sdk]
  2.1.100 [C:\Program Files\dotnet\sdk]
  2.1.101 [C:\Program Files\dotnet\sdk]
  2.1.102 [C:\Program Files\dotnet\sdk]
  2.1.103 [C:\Program Files\dotnet\sdk]
  2.1.104 [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-007513 [C:\Program Files\dotnet\sdk]
  2.1.200-preview-007517 [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.300 [C:\Program Files\dotnet\sdk]

How do I remove the old cruft (especially the previews)?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:17 (7 by maintainers)

github_iconTop GitHub Comments

46reactions
penguidcommented, May 23, 2019

And here is a script function that attempts to silently uninstall (except for UAC prompt) outdated SDKs, keeping only the latest patch version of each (unless using the -All param). Dry run with Uninstall-DotNetSdk -WhatIf or Uninstall-DotNetSdk -WhatIf -All.

function Uninstall-DotNetSdk {
  param (
    [parameter(Mandatory = $False)] [switch] $All,
    [parameter(Mandatory = $False)] [switch] $WhatIf
  )
  pushd $env:SystemRoot\System32
  Get-ChildItem HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall |
    Get-ItemProperty |
    Where-Object DisplayName -match "^Microsoft .NET Core SDK" |
    Where-Object BundleVersion -match "^\d+\.\d+\.\d+\d\d\.\d+$" |
    Group-Object { ([regex] "^(\d+\.\d+\.\d+)\d\d\.\d+$").Match($_.BundleVersion).Groups[1].Value } |
    Sort-Object { [regex]::Replace($_.Name, '\d+', { param($match) $match[0].Value.PadLeft(10,'0') }) } |
    ForEach-Object {
      $_.Group |
        Sort-Object {
          $versionMatch = ([regex] "^\d+\.\d+\.\d+(\d\d)\.(\d+)$").Match($_.BundleVersion)
          $v1 = $versionMatch.Groups[1].Value
          $v2 = $(if ($versionMatch.Groups[2].Value -eq "0") { "9".PadLeft(10,'9') } else { $versionMatch.Groups[2].Value.PadLeft(10,'0') })
          "$v1.$v2"
        } |
        Select-Object -SkipLast $(if ($All) { 0 } else { 1 }) |
        ForEach-Object {
          if ($_.QuietUninstallString -imatch '^"?([^"]+)"? +(/uninstall.*)$') {
            $file = $Matches[1]
            $arglist = $Matches[2]
            "Uninstall command: `"$file`" $arglist"
            if (-not $WhatIf) { Start-Process -FilePath $file -ArgumentList $arglist -Wait }
          }
        }
    }
  popd
}
19reactions
turowiczcommented, Oct 26, 2018

How do we do this for Mac or Linux?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Remove the .NET runtime and SDK
To remove a Snap package, use the snap remove <package> command. For example, to remove .NET Runtime 3.1, use snap remove dotnet-runtime-31 ....
Read more >
Removing old version of .NET
To remove the unuseful version of the SDKs and runtimes, you can use the dotnet-core-uninstall tool. It's not installed by default but you ......
Read more >
How to uninstall .NET SDK previews and older versions ...
I'd like to uninstall .NET 5 and .NET 6 previews - and just keep the latest .NET 6. However, the uninstall utility only...
Read more >
How to remove old .NET Core SDKs? · Issue #2295
The .NET Core command-line (CLI) tools repository provides uninstall scripts. Linux (yum): dotnet-uninstall-rpm-packages.sh ...
Read more >
Clean up some .NET Clutter
Uninstall the .NET SDKs and RuntimePermalink ... There are quite a few different ways to uninstall the .NET SDKs and Runtime's. For each...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found