The other day after installing some windows update, I tried to open Visual Studio. I opened my project and I received an error regarding .Net Sdk.
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.
It was kind of frustrating because I didn’t install anything new I just installed some windows update. Also this can happen for different reasons. So I thought this made me pull my own hair out, maybe by sharing this you don’t have to go through the same.
The .Net Sdk Is Not Actually Installed
First things first, removing some low hanging fruits. First wee need to see if the Sdk is actually installed. Navigate to
C:\Program Files\dotnet\sdk and see if you can find folders associated with different sdk versions. If you can’t find any folder there that means the sdk is not installed. In that case Install the sdk or repair it if you receive a message about it being already installed. Try running
dotnet --list-sdks command to see if it lists the sdk.
The .Net Sdk Is Installed But it Has Wrong System Type
The thing about the Sdk is that you can’t mix 64x with 86x versions of the sdk. Technically you can but you need to be careful which version of dotnet is going to be selected first. More on this in next section. But if an sdk is installed, be careful you have the correct system type.
The .Net Sdk is Installed But Wrong Dotnet CLI is Trying to Run It
Sometimes you check your dotnet sdk folder and you see the sdk are installed. But when you run
dotnet --list-sdks you don’t see anything. In that case try running
list-sdks command with an absolute path to the correct version of
dotnet. Like C:\Program Files\dotnet dotnet –list-sdks, if after running this you see the installed sdk then there are some path problems. You need to check your environment variables to make sure the correct version of dotnet is on your path. More on that in next section.
Dotnet CLI is Not on Your Path (System’s Environment Variable)
We need to first see how dotnet CLI is selected to run our commands. Take a look at this environment variables.
We see here that x64 version of the dotnet is above the x86 version of it. That means the x64 version is going to be selected to run my commands. So now if I only install the x86 version of the sdks, I’m going to have a problem. Because the x64 version of dotnet is unable to use the x86 sdks. What I need to do is to either install the x64 version of the sdk or move the x86 version above x64 version so it can be selected first.
Further Reading and References
Dotnet list-sdks does not list the installed SDKs
Microsoft Visual Studio 2019: The project file cannot be opened. Unable to locate the .NET SDK
.NET SDK not found after successful install
“No SDKs were found” after install “dotnet-hosting-2.1.2-win.exe”
Adventures in .NET Core SDK Installation: Missing SDKs and 32 bit vs 64 bit
In this post we saw why sometimes the correct sdk is not found on your system. We saw different things we can check for in these cases and how to fix them.