Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 884
RickAndMSFT Avatar asked Apr 11 '21 19:04

RickAndMSFT


People also ask

Where is .NET SDK installed on Windows?

NET 6 SDK, it's installed to the C:\Program Files\dotnet\x64\ folder.

How can I tell what version of .NET SDK is installed?

You can see both the SDK versions and runtime versions with the command dotnet --info . You'll also get other environmental related information, such as the operating system version and runtime identifier (RID).

Does Visual Studio install .NET Core SDK?

NET Core can be installed in two ways: By installing Visual Studio 2017/2019 or by installing . NET Core Runtime or SDK. . NET Core installer already contains ASP.NET Core libraries, so there is no separate installer for ASP.NET Core.


1 Answers

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

like image 92
RickAndMSFT Avatar answered Sep 18 '22 15:09

RickAndMSFT