'Windows or Visual Studio can't find the latest installed .NET SDK due to bitness

I've successfully installed the latest .NET SDK, but Windows doesn't recognize it. This is manifested by one of the following failures:

  • dotnet --list-sdks doesn't include the latest .NET SDK.
  • Windows x64 can't find .NET 5 or .NET 6.
  • Visual Studio can't find the latest SDK or throws one of the following errors when trying to open a project:
    • Project 'MyProject' load failed: The specified SDK "Microsoft.NET.Sdk" was not found.

    • Unable to locate the .NET SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version

    • The current .NET SDK does not support targeting .NET Core N.N. Either target .NET Core N.M or lower, or use a version of the .NET SDK that supports .NET Core N.N

How can I get Windows to recognize the latest installed version of the .NET SDK?



Solution 1:[1]

Run where dotnet from the command line. If the output is similar to:

C:\Program Files (x86)\dotnet\dotnet.exe
C:\Program Files\dotnet\dotnet.exe

Then both the 32-bit and 64-bit versions of the SDK have been installed at some time.

32 bit --- C:\Program Files (x86)\dotnet\dotnet.exe
64 bit --- C:\Program Files\dotnet\dotnet.exe

The first SDK installed on the computer puts the dotnet path in the system path. Any subsequent SDK install of a different bit size SDK also adds dotnet path to the system path, but after the first dotnet path. Therefore, only SDK's of the first bit size are available by default, using the path variable.

There are two approaches to fixing the problem:

  1. Install the latest SDK with the other bit size. This is the easiest solution.
  2. Change the order of C:\Program Files (x86)\dotnet\dotnet.exe and C:\Program Files\dotnet\dotnet.exe in the System environment variables path:

Select the windows key and enter Edit, then select Edit the system variables enter image description here

Select the Environment Variables button on the Advanced tab:

enter image description here

Select the Path > Edit under System variables (not User variables).

enter image description here

Find the entries for C:\Program Files\dotnet\dotnet.exe (64 bit) and C:\Program Files\dotnet\dotnet.exe (32 bit) and using the Move up button, change to order. Here's an example:

enter image description here

Select the OK button until all the windows are closed. Open a new command prompt and run where dotnet.

Answer from https://github.com/dotnet/core/issues/5962 More details at https://weblog.west-wind.com/posts/2019/Apr/20/Adventures-in-NET-SDK-Installation-SDKs-not-Showing-Up

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 zellus