Microsoft Visual Studio 2019: The project file cannot be opened. Unable to locate the .NET SDK

C#Visual Studioasp.net Core.Net Coreasp.net Core-3.1

C# Problem Overview


I just upgraded my visual studio 2019 to latest version 16.8.3 and suddenly I am not able to load any C# project and getting the following error for all .NET core projects:

> The project file cannot be opened. 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.

C# Solutions


Solution 1 - C#

Try to edit envrionment Variables.

Right click on This PC -> Properties -> Advanced System Settings -> Advanced -> Environment Variables -> System Variables

Add [install path] C:\Program Files\dotnet\ to the variable path.

Restart visual studio.

If it does not solve this problem, you can refer to this answer.

Solution 2 - C#

I found that the path C:\Program Files\dotnet was already in my path but it was ordered below the C:\Program Files (x86)\dotnet entry. By simply moving C:\Program Files\dotnet above C:\Program Files (x86)\dotnet in the list and restarting Visual Studio cleared up the problem.

Solution 3 - C#

If there is a global.json file in your solution folder(where *.sln file reside), delete this.

Solution 4 - C#

In my case, I had .NET 6 preview but then uninstalled it. After uninstalling, some of my projects won't load. I have all the configurations mentioned above but still won't load the projects. I went to C:\Program Files\dotnet\sdk\ where I found that there still exist a .NET 6 folder which is empty. Deleting that empty .NET 6 folder fixes the issue and I was able to load my projects.

Solution 5 - C#

This works for me... Check first if which .net Core SDK is available in the system.

Step 1: Open Command prompt (CMD) and type dotnet --info

enter image description here

The above image shows no SDK is installed or register

Step 2: Install SDK from https://dotnet.microsoft.com/download/dotnet-core

Done Visual studio works like charm... Verify if its properly installed and register

enter image description here

Above image you can see .net core SDK is registered properly on the system.

Solution 6 - C#

I had a similar situation upgrading from VS 2019 to VS 2022, trying to run a dotnet 5.0 solution from VS 2022 (that starts to use dotnet 6.0).

In the PATH env. variable I had both 'C:\Program Files\dotnet' and 'C:\Program Files (x86)\dotnet'. I removed the (x86) one and stopped having that error

Solution 7 - C#

I just deleted C:\Program Files\dotnet folder and it work's for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDadwalsView Question on Stackoverflow
Solution 1 - C#Karney.View Answer on Stackoverflow
Solution 2 - C#stidhatView Answer on Stackoverflow
Solution 3 - C#Ahmet ArslanView Answer on Stackoverflow
Solution 4 - C#LanceView Answer on Stackoverflow
Solution 5 - C#Krunal SolankiView Answer on Stackoverflow
Solution 6 - C#brunochainaView Answer on Stackoverflow
Solution 7 - C#VictoriaView Answer on Stackoverflow