Install dotnet sdk latest release of a specific major Version

238 views Asked by At

I have a task of installing latest 6.x.x version of dotnet-sdk on powershell. We are currently using chocolatey to install the pinned sdk version but chocolatey doesnt suppport wildcards.

Current Code :

choco install dotnet-sdk --version 6.0.302

I have to install latest release from version 6.

I referred to this page https://dotnet.microsoft.com/en-us/download/dotnet/6.0 but couldnt convert the installation to script.

2

There are 2 answers

1
Panagiotis Kanavos On BEST ANSWER

If you really want to use Chocolatey, install the dotnet-6.0-sdk package without a version :

choco install dotnet-6.0-sdk

As the docs explain:

This is a metapackage, which installs the latest release of .NET 6.0 SDK across all feature updates.

.NET SDK isn't deployed through Chocolatey. What you find there is a metapackage that downloads and installs the actual installation package. The maintainers of those packages ensured there's both an overall package, dotnet-sdk and packages specific to major versions like dotnet-6.0-sdk. Every time a new SDK is released, the maintainers update the packages.

Another option is to download and use the official .NET installation scripts. There's always a link in the .NET SDK download page, that links to the script download page and the documentation If you don't need Chocolatey, you can use the Powershell .NET installation scripts found in the .NET download page.

0
mklement0 On

Just to offer an alternative to using Chocolatey for the installation.

You can also install .NET SDKs via winget.exe, the Windows Package Manager CLI:

# Installs the latest .NET 6 SDK.
# Run From an ELEVATED session.
winget install Microsoft.DotNet.SDK.6 -h
  • The -h (--silent) option hides the installer's GUI.

    • Caveat: If you run the command without elevation (not from a session started with Run As Administrator), you'll still get one GUI element, namely the UAC dialog for on-demand elevation. In combination with -h this dialog doesn't pop up; you need to activate it manually, via the task bar, in order to respond.
  • To also hide winget's own console output, append *>$null

  • The above works analogously for other major .NET SDK releases, e.g. Microsoft.DotNet.SDK.8; to find them all, run:

    winget search Microsoft.DotNet.SDK.
    
  • To later remove (uninstall) an SDK installed this way, use, e.g.:

    # Uninstall.
    # Run From an ELEVATED session.
    winget uninstall Microsoft.DotNet.SDK.6 -h