18

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, .NET 6, or .NET 7.
  • 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 N.N. Either target .NET N.M or lower, or use a version of the .NET SDK that supports .NET N.N

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

RickAndMSFT
  • 20,912
  • 8
  • 60
  • 78

1 Answers1

43

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

zellus
  • 9,617
  • 5
  • 39
  • 56
RickAndMSFT
  • 20,912
  • 8
  • 60
  • 78
  • 1
    In my case the where command did not present anything and it seems that Visual Studio 2019 simply did not add the `C:\Program Files\dotnet` and `C:\Program Files (x86)\dotnet` file paths to my System Path Environment Variable. So, the second part of your solution was applicable. Thank you! – JLunda Oct 28 '21 at 19:25
  • Keeping my fingers crossed but it looks like the 17.7.1 update works out of the box No more messing around with environment variables – plykkegaard Aug 17 '23 at 14:32