user3458219
user3458219

Reputation: 151

Unable to locate the .NET core SDK

I have a .NET core solution project targeting .Net core 2.1.

In my new machine, VS 2019 has been installed(.Net core 3.1.101 is installed with VS 2019)

Now when I try to run the project it says version 2.1 was not found.

So I installed/uninstalled different .Net core 2.1 SDKs.

Finally, I have below SDKs installed in my machine.

  1. 2.1.809
  2. 3.1.101

Now while opening the solution, none of the project loads and I see the below error in the output window:

'Unable to locate the .Net core SDK, check that it is installed and version specified in global.json matched with the installed version.'

I don't have global.json in my project. Though I created the dummy one and provided SDK version 3.1.101 in that; however, it didn't work.

How can I know which version my project is trying to get and throwing this error?

Upvotes: 1

Views: 7448

Answers (4)

Ester Kaufman
Ester Kaufman

Reputation: 868

For anyone else encountering this issue, maybe this could help.
This instructions is for Rider but I believe its the same also for VisualStudio.

Go to Help -> Find Action -> type:"Manage .Net SDK".

This should open the "Manage .Net/.Net Core SDK for Solution" window.
Then,
you can select from the list of installed versions, which one you want.

OR - what I did,
I select in Roll-forward policy input, latest minor, which trying to find the installed version with the most updated number in minor.

For Example:
The solution expected .Net 6.x, but with latestMajor it found the .Net 7.x installed and try to use it for this solution.
With latestMinor, it selected the latest 6.x installed on my PC, and success to works with it.

Manage_sdk_for_solution

Upvotes: 1

Abdullah Akhtar
Abdullah Akhtar

Reputation: 558

Step 1

Install Visual Studio Installer

VS Installer should be related to your VS version i.e. 2019/2020/2022

Step 2

If you have installed multiple Visual Studio Versions, all will appear. Look for the one you are using or the one which is not opening the project.

for example I have only Visual Studio 2019 installed so it will only show me VS 2019 else there will be 2021 2022 versions available.

Step 3

There you will see the options to Modify / Uninstall / Update. Update from there, you don't have to delete your project or update anything else. From here, it will update all the necessary items and removes the one not needed.

Removing the items by the VS installer doesnot effects anything. It just replace the new updates available.

Once it is done updating, Project will load successfully and it automatically update .Net core SDK and adds the updated version to global.json

Upvotes: 0

TPG
TPG

Reputation: 3201

For my case, it works while checking dotnet --version, dotnet --list-sdks etc. Environment variables also set correctly. Everything looks fine but when I tried to Load the Xamarin Forms project, it keep throwing this error.

Even if I create new Xamarin Forms project, the Android and iOS are there, but the Forms failed to load.

After trying here and there, my solution was to delete the folder at C:\Program Files (x86)\dotnet, because I have already got the working Core at C:\Program Files\dotnet. I think Visual Studio looked for the library at x86 first, before trying in x64.

Now it works.

Upvotes: 3

user3458219
user3458219

Reputation: 151

Re-installation of VS 2019 solved the issue of loading projects.

After re-installation VS 2019 is upgraded to 16.7.2 and .NET Core SDK to 3.1.401.

Now to successfully run the project targeting .NET core 2.1, I installed .NET Core SDK 2.1.810.

dotnet.microsoft.com/download-visual-studios-sdks - This can help which version to install.

Upvotes: 0

Related Questions