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

10

95

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.

Peddada answered 9/12, 2020 at 1:53 Comment(1)
Do you perhaps have a global.json file somewhere in the file system (in a common folder beneath all your failing projects) that is specifying an SDK version that no longer exists on your computer? If so: try renaming/deleting that file! (To be fair, the error message did suggest this)Commander
N
182

Try to edit environment 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.

Nnw answered 9/12, 2020 at 6:4 Comment(10)
Path [C:\Program Files\dotnet] is already there. Though I removed the x86 one and it started working, ThanksPeddada
Removing the path as @Peddada did resolve the issue for me.Radiophone
I edited the C:\Program Files (x86)\dotnet to what Karney listed above and it fixed it for me! Thank you!Formless
Thank you!! FWIW, I encountered this error after removing a ton of old .Net Core SDKs, and this resolved it. Possibly one of those uninstallers removed the Path variable.Peso
In my case I have two installations in the folders C:\Program Files\dotnet\ and C:\Program Files (x86)\dotnet\ , so i had to add the adrdress like this C:\Program Files\dotnet\sdk in my System Variables.Fuqua
I have so many darn items in my Path environment variable that the latter half of the list is ignored. I moved this entry to the top and bingo!Barbarian
Just follow this - github.com/dotnet/sdk/issues/14139#issuecomment-963943549Hyaluronidase
Recently a software installation managed to replace my whole and pretty long PATH variable just with a single entry pointing to the software's install directory (thanks devs) and adding the mentioned dotnet path to the PATH variable fixed compiler errors for me.Endanger
This worked for me, also the .NET SDK for my project was not installed and continued to show the same error until after I installed the SDK referenced in the solution project file "TargetFramework" element e.g. netcoreapp3.1 / net6.0-windows. The SDK's earlier than .NET 6 aren't listed on the .net download page and I found it on the official release history page: versionsof.net/corePrig
Thank you! I installed SSMS19.2 which required a reboot so I closed my VS solutions. Rebooted and SSMS 19.2 worked fine so I then opened a VS solution and I got the error above. I added to my "path" variable as you described and it worked again. Thank you for this solution!Champaign
F
96

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.

Fledgling answered 27/1, 2021 at 18:50 Comment(4)
Just had to do this after updating to Version 16.10.4. SMH @MSFTBrusque
Same was the issue on my machine. But I was fiddling with user path for a long time, unable to understand what's happening. Then I found this order issue in System Paths, fixing which solved the issue for me.Ebracteate
Thanks. This worked for me.Tica
After installing SDK and runtime from dotnet.microsoft.com/en-us/download/dotnet/3.1 and followed this step solved my issue...Apfelstadt
A
24

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

Athanor answered 16/5, 2021 at 20:44 Comment(0)
D
21

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.

Demodulator answered 4/10, 2021 at 22:10 Comment(3)
that was the solution for me..I had 6.0.200 and after I've updated VS I got the 6.0.300. The projects were not loading with the message that the SDK is not installed. I've deleted the 6.0.200 that had an almost empty folder. and that was it. Thanks.Territoriality
In my case the folder 6.0.402 was still there because I've manually added some stuff there before. This was probably the reason it wasn't removed automatically. I was however "almost" empty – only manually added stuff was still there.Toothbrush
Also restart visual studio after the empty folder is deletedGiuseppe
G
11

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.

Gens answered 10/2, 2021 at 5:37 Comment(0)
S
4

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

Syncrisis answered 9/11, 2021 at 18:36 Comment(0)
R
1

Installing missed SDK that the project has built solved the problem

I had a similar issue when I tried to build a net5.0 solution that is not installed on my machine.

In my case, I had VS 2022, and net6.0 installed.

Installing net5.0 SDK solved the problem.

I had only C:\Program Files\dotnet in Path env

Roadrunner answered 17/6, 2022 at 17:17 Comment(0)
V
1

Had this when MS Updated updated the dotnet sdk, but left the folder of the older version (7.0.102) in place (containing only folder "Roslyn" inside). Deleting the leftover fixed the problem for me.

Worth noting that I had newer version's folder 7.0.111 with valid structure alongside 7.0.102

Vacant answered 29/9, 2023 at 14:31 Comment(0)
T
0

I just carefully followed the error message and tried to resolve the problem.

I got below error message:

F:\mypath\ServerlessFunc\ServerlessFunc\ServerlessFunc.csproj : error : The project file cannot be opened. C:\Program Files\dotnet\sdk\6.0.402\Sdks\Microsoft.NET.Sdk\Sdk not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.

I then tried to navigate through

C:\Program Files\dotnet\sdk\6.0.402\Sdks\Microsoft.NET.Sdk\Sdk

path which was mentioned in the above error and found that the above path does not exist. This problem could be resolved if I install SDK of version of 6.0. Rather I started using VS-2022.

Transcaucasia answered 12/11, 2022 at 4:5 Comment(0)
S
0

I had this issue for only a couple of projects in my solution! Resolved it by downloading and installing the appropriate SDK for my solution - .net SDK 5.0 (X64) for VS 2019.

Choose the appropriate ones for your projects & give this a try. https://dotnet.microsoft.com/en-us/download/visual-studio-sdks

Screening answered 7/2 at 6:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.