找不到global.json指定的.NET SDK,请检查是否安装了指定的版本

6tqwzwtp  于 2022-12-14  发布在  .NET
关注(0)|答案(3)|浏览(520)

trying to start a .NET console application. Would prefer F# but get the same error in C# or VB as well.
Unable to locate the .NET SDK as specified by global.json, please check that the specified version is installed . I get that warning as soon as I create a new application, and get it as an error when I try to build.
This is using the default Hello World templates that come with Visual Studio. I would expect the prebuilt templates that ship with the app to build first time. Using VS 2019 16.8.5.
I have searched Visual Studio project and the source directory and can't find any global.json.

EDIT: Found the global.json at C:\users\username

{
  "sdk": {
    "version": "3.1.300",
    "rollForward": "latestMinor"
  }
}

Which I'm fairly sure I have the SDK installed for but will double check.

6qfn3psc

6qfn3psc1#

In my case my global.json was referring to an SDK I didn't have. Run the below in your terminal

dotnet --list-sdks

That will give you the list of all the SDK's available, here you can either update your global.json file to the version you have (or install the missing SDK if you need to)

b1uwtaje

b1uwtaje2#

I would advise removing that global.json file instead of just adding latestMajor to it, since it's in a place where it probably shouldn't be. Having one in the root of C:\users\your-name with that value is functionally equivalent to not having it in the first place.
The general purpose of a global.json file is to lock down the SDK version used for a specific codebase. For example, this can be helpful if you're using a CI system that can install a .NET SDK based on a global.json file, so you don't have multiple places to update your toolset over time.

rqdpfwrv

rqdpfwrv3#

Check rollForward is disabled or not If disabled the make it latestMinor

"rollForward": "latestMinor"

相关问题