dotnet core 3.0 unable to locate the dotnetcore sdk when opening solution in vs

Viewed 10387

I am trying to load the source code for ASP.NET Core MVC at https://github.com/aspnet/aspnetcore. However, when I cloned the project, checked out v3.0.0, and tried to open the solution in Visual Studio 2019 (v16.3.4), I got the following error for all the projects

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 ensured the .net core 3.0 sdk has been downloaded on my computer, and running dotnet --info yields the following data:

Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

Looking in the .csproj file, they are all targeting

<TargetFramework>netcoreapp3.0</TargetFramework>

Additionally, I have ensured that the path to the SDK 'C:\Program Files\dotnet' is included in my PATH variable. I tried adding a global.json file specifying the sdk, but it didn't seem to make a difference.

Any idea what could be causing this issue?

Edit

Below is an example of the csproj file

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <Description>ASP.NET Core metadata.</Description>
    <TargetFramework>netstandard2.0</TargetFramework>
    <IsAspNetCoreApp>true</IsAspNetCoreApp>
    <IsShippingPackage>true</IsShippingPackage>
    <NoWarn>$(NoWarn);CS1591</NoWarn>
    <GenerateDocumentationFile>true</GenerateDocumentationFile>
    <PackageTags>aspnetcore</PackageTags>
  </PropertyGroup>

</Project>

, and here is the folder with all the SDKs on my machine. enter image description here

9 Answers

I have same issue and I found the solution; I hope you have the same issue as I do.

cmd -> input dotnet --info
copy .Net Core's "Base Path"
Just add it to your system's Path variable.

The variable name is MSBuildSdksPath

More details, you can check this https://github.com/aspnet/Announcements/issues/231

Some possible causes:

  • you need to restart the computer, because the environment variables are cached
  • you need to restart Visual Studio, because Visual Studio caches, too (close all instances of it)
  • you have installed the 64-Bit version of the SDK, but you need the 32-Bit SDK, or vice-versa.
  • you have installed an old preview sdk, and need to enable preview versions in the options of Visual Studio (or download the non-preview SDK since it's RTM)

You could try one trick I learned:
Open a command line prompt, and type env
get the path environment variable

It should have

C:\Program Files\dotnet\;
C:\Program Files (x86)\dotnet\;

in it.

Now replace C:\Program Files\dotnet\; with D:\Programs\LessPortableApps\dotnet\, where D:\Programs\LessPortableApps\dotnet\ is the folder where you put your dotnet-sdks in.

Then, set the path environment variable SET PATH="bla" to your new path, with the dotnet folders replaced.

And then start Visual Studio from the command prompt, e.g. :

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe

That way, you can use .NET SDKs when you don't have admin rights to install them.

One more thing:
.NET Core 3.0 requires Visual Studio 2019, if you have 2017, you can only use it, if you have msbuild installed (same version as VS2019).

To install the latest (as of 2019) stand-alone MSBuild, go to: https://www.visualstudio.com/downloads/ and Scroll down to "Tools for Visual Studio 2017" and choose "Build Tools for Visual Studio 2019" (it's for users who don't want the full IDE)

Direct link

For me, I downloaded the master branch in a zipped file from https://github.com/dotnet/aspnetcore. Then I ran into the same issue when trying to load AspNetCore.sln in VS Code. (All projects in the solution failed to load).

Using dotnet --info I see that I have these installed:

3.1.201 [C:\Program Files\dotnet\sdk]
3.1.402 [C:\Program Files\dotnet\sdk]
3.1.403 [C:\Program Files\dotnet\sdk]

However, the SDK version specified in global.json in the solution folder is using 6.0.100-alpha.1.20523.3.

{
  "sdk": {
    "version": "6.0.100-alpha.1.20523.3"
  },
  "tools": {
    "dotnet": "6.0.100-alpha.1.20523.3",
    ...other settings...
  }
}

So I changed both settings to "3.1.403". Upon reloading the solution, all projects loaded properly.

dotnet sdk tools looks for global.json file in the current working directory or the parent directories The dotnet SDK version defined in the global.json indicates which versions of the .NET CLI should be used. In general latest dotnet sdk tools are used so no global.json is needed. So if you want to controll which version of cli to use then add global.json else it is not needed.

try deleting global.json from your project directory or the parent directories and tooling will default to latest available sdk tool

a typical global.json file content looks something like below

{
  "sdk": {
  "version": "3.1.102",
  "rollForward": "latestFeature"
  }
}

dotnet --list-sdks if you dont sdk download it. enter image description here

The problem for me was, I have dotnet 5.0.103 version installed in my system, and in my global.json (path for global.json file - C:\Users\userid\global.json) file the version was set "version": "3.1.100".

After updating the path from "version": "3.1.100" to "version": "5.0.103", it started working again.

dotnet sdk version

global.json

Related