Original Source Link
I’m following this tutorial – Share Azure Spatial Anchors
across sessions and devices – at Microsoft Docs.
It requires I open a project in VS,
but when I try to open it I get the following error:
error : The project file cannot be opened by the project system,
because it is missing some critical imports or the referenced SDK
cannot be found.
Detailed Information: Unable to locate the .NET Core SDK. Check that
it is installed and that the version specified in global.json (if any)
matches the installed version.
I have the SDK version specified in the JSON
and all the other tools specified in the tutorial, but still nada.
I think I’m missing a step somewhere. Any help would be hugely appreciated.
Step 1) First run
dotnet --list-sdks from the command line (as in Grzegorz Smulko’s answer). Take note of the greatest version number.
Step 2) Create a global.json file at the root of the solution with the exact version number from step 1. it needs to contain all the digits otherwise it wont work. This is the my version at the time of writing
dotnet --list-sdks in the console.
According to the info on the pages that appear after downloading .NET Core SDKs from https://dotnet.microsoft.com/download, you need to have version v2.2.106 for VS2017 and v2.2.203 for VS2019.
With only the v2.2.203 installed projects didn’t load for me in VS2019.
I had to install v2.2.105 too.
I fixed it by installing the x86 version of the SDK.
It looks like each version of Visual Studio has it’s own corresponding dotnet version that it builds on. This is due to msbuild requirements.
If you are a Visual Studio user, there are MSBuild version requirements so use only the .NET Core SDK supported for each Visual Studio version. If you use other development environments, we recommend using the latest SDK release.
As detailed on that page, you’ll need the following versions of dotnet for each visual studio version:
- Visual Studio 2017 (Windows): .NET Core SDK x86 2.2.108
- Visual Studio 2019 version 16.0: .NET Core SDK x86 2.2.205
- Visual Studio 2019 version 16.1: .NET Core SDK x86 2.2.301
- Visual Studio 2019 version 16.2: .NET Core SDK x86 2.2.401
I had this problem because I uninstalled some older dotnet SDKs. Not only would VS2019 no longer load dotnet core projects, but
dotnet was no longer available on my path and so not available on the command line as simply
After installing multiple older versions of dotnet and reparing my VS2019 install, I was finally able to fix it by adding
C:Program Filesdotnet to my path. Then VS2019 would load the project again.
Also, none of this affected VS2017, which could load and fully work with the project. And it worked on the command line when I specified the full path to the dotnet executable.
None of the above worked for me. I noticed that I was having the issue on every type of project, even non-netcore. I was able to use the global.json and get that working. Then I noticed that I had a global.json in a directory further up which was referencing an alpha build of .net core. Deleted that file and bingo no further issue.
Make sure that there are no global.json files further up in your directory structure that are screwing things up.
I had the same error a while back which caused my web api projects to fail during the solution loading process.
I solved it by reinstalling the following items from https://dotnet.microsoft.com/download
- .Net Core Runtime (2.2.401 was the latest at the time)
- .Net Core SDk (2.2.6 was the latest at the time)
I faced this problem in vs 2019 v16.3
I have uninstalled old versions of netcore 2.1 SDK except version 2.1.801.
I found a file global.json in the folder: c:Usersadmin (my login user is admin) that point to uninstalled version 2.1.602
Although netcore SDK version 2.1.801 is installed, it’s not used because it doesn’t match the Patch number.
The patch version is defined by the last two digits (yz) in the last portion of the number (xyz) for SDK versions 2.1.100 and higher. For example, if you specify 2.1.300 as the SDK version, SDK selection finds up to 2.1.399 but 2.1.400 isn’t considered a patch version for 2.1.300.
I modified the file to point to 2.1.801 and it’s working fine
In my case, remove program files(x86)dotnet in Environment path then restart visual studio and it worked.
I was able to fix the VS 2019 issue with the below steps
dotnet --list-sdks to know the exact version of the SDK installed
- Modify the global.json file in the root folder of the project (In my case it was showing 2.2.100 but I had 2.2.401 installed, I edited the same to point to that version and I was able to reload the projects
I found the same issue. It was releated with this bug https://github.com/dotnet/core-setup/issues/4236
That seems to be a bug in dotnet x86 version.
I just changed x64 dotnet (C:Program Filesdotnet) to be before x86 dotnet (C:Program Files (x86)dotnet`) in the %PATH% environment variable and it worked just fine.
I tried everything listed in the answers with the same error in VS 2019 and ultimately the thing that wound up fixing it was following these steps:
Right-clicked on Solution and hit ‘Resolve Errors’
I spent a full day installing and uninstalling various .net packages and of all the things, that’s the one that got it to build.
…If Microsoft can tell where an error is, why doesn’t it just try to resolve it automatically?!
I ran into this today, where a solution has some (but not all) the projects using .net core; I had not been into this project in probably a month and had not intentionally done anything with the .net SDKs, so this was a mystery what the heck happened.
My project has no
global.json at the root, creating one with the the latest (3.1.201) from
dotnet --list-sdks didn’t help. WTF?
Then I found this: https://developercommunity.visualstudio.com/content/problem/896868/unable-to-locate-the-net-core-sdk-after-1650-previ.html
Visual Studio now removes previous .NET Core SDKs. If you encounter this problem, you can:
– Install .NET Core SDK from https://dotnet.microsoft.com/download.
global.json. The latest version of the .NET Core SDK is the default and can build apps targeting earlier versions of the .NET Core Runtime.
Include a roll forward indicator (in
global.json) such as the following which will ensure running with any SDK higher than 3.1.100 [see link for details]
A routine install of the latest .NET sdk (3.1.300) resolved this issue, but this feels like really poor behavior of Visual Studio – if it can’t find an SDK, maybe tell us which one it’s looking for? Ugh.