27

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.

10 Answers 10

33

stick a global.json file at the root of the soloution with the version that you need, it needs to contain all the digits. This is the latest version at the time of writting

{
  "sdk": {
    "version": "2.2.300"
  }
}
  • This fixed my problem, but I don't know why! I have other projects without this file that are working. – CSharper Jul 4 '19 at 9:51
  • 1
    Though this file exists, I need to update the version – Gopi Jul 9 '19 at 7:09
  • 2
    Cheers, while this helps, I found out that VS 2019 stops opening .net core projects when you don't have installed 2.2.205 version. Using global.json is just inconvenient and tool should not rely on it. It should use the latest version of whatever target. MS is trying us again. – Stefan Jarina Jul 26 '19 at 18:34
  • 2
    As per @Gopi, I found that the file did exist in the root folder, but the version number in it was for an old SDK that I did not have installed. I ran "dotnet --list-dsks" to find the most recent and updated the file with the correct SDK number. The solution then loaded. – Glen Little Aug 28 '19 at 21:20
14

Try running 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.

  • 2
    This should be accepted answer as that is exactly what is happening. I have currently installed 2.2.205, 2.2.301, 2.2.401, 3.0.100 --- However if you remove the 2.2.205 Visual Studio 2019 will just break (won't open ANY .net Core 2.2 projects) even though you have already newest 2.2.401. – Stefan Jarina Jul 26 '19 at 18:27
  • THIS is the permanent fix, not adding "global.json". The specific versions are here: dotnet.microsoft.com/download/dotnet-core/2.2 – Salar Oct 29 '19 at 3:11
  • This answer suffers from not being written in such a way will be accurate in the future, for instance, it’s currently out of date. Which is the reason modifying global.json is the way to go. The author first said v2.2.106 was required but it didn’t work until v2.2.105 was installed. – Ramhound Dec 24 '19 at 9:24
6

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 dotnet.

After installing multiple older versions of dotnet and reparing my VS2019 install, I was finally able to fix it by adding C:\Program Files\dotnet\ 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.

  • 1
    Very helpful! In my case, which is reversed: I have 2 paths point to program files\dotnet and program files(x86)\dotnet, I removed sencond one, then visual studio get able to load projects. – Dongdong Oct 29 '19 at 18:25
  • today, I found real reason. when I remove second path, the 1st path started working, and projects could be loaded. but once when I switched to another solution which has a global.json, and that json specify a different version of SDKs, then VS will no longer to load both projects. what I did is simply remove global.json, then both solutions start working. so the key reason is: you have right SDK version installed which specified by global.json. – Dongdong Oct 30 '19 at 17:30
6

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.

https://github.com/dotnet/core/blob/master/release-notes/2.2/2.2.6/2.2.6.md

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
2

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)
2

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:\Users\admin (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.

from documentation:

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

1

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.

tl;dr: Make sure that there are no global.json files further up in your directory structure that are screwing things up.

0

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 Files\dotnet) to be before x86 dotnet (C:\Program Files (x86)\dotnet`) in the %PATH% environment variable and it worked just fine.

  • 1
    Welcome to Super User! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference. – bertieb Aug 6 '19 at 14:59
  • @bertieb, done :) – bruno.almeida Aug 9 '19 at 8:44
0

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?!

0

In my case, remove program files(x86)\dotnet in Environment path then restart visual studio and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.