Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

npm cannot find SDK version from global.json

I'm in the thick of trying to get up-to-speed on asp.net core / npm / react using this as a base project template:

https://github.com/jonmcquade/aspnetcore-react-redux#local-no-docker

I originally ran into troubles once trying this command:

dotnet build -c Release -o ./app

The error I was seeing:

A compatible SDK version for global.json version: [2.1.0] from [global.json] was not found Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
http://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409

I had the specific versions in the documentation installed and I have installed the latest versions, both x64 and x86 platforms.

enter image description here

I now also get this error running the npm install command or the dotnet --version command, yet I have SDKs installed.

It feels like the machine configuration has become broken somehow. I seem to have gotten into a bit of a version pickle trying to get the dotnet build command working and now even NPM isn't working.

Global.json is:

{
    "sdk": { "version": "2.1.0" }
}

And the .csproj file contains:

  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <RuntimeFrameworkVersion>2.1.0-preview1-26216-03</RuntimeFrameworkVersion>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    <IsPackable>false</IsPackable>
    <AssemblyName>FlightSearch</AssemblyName>
    <RootNamespace>FlightSearch</RootNamespace>
    <ApplicationIcon>ClientApp\favicon.ico</ApplicationIcon>
    <Authors>Jon McQuade</Authors>
    <Company>ACME Freelancing, Inc.</Company>
    <StartupObject></StartupObject>
    <Product>Flight Search</Product>
    <Description>ASP .NET Core 2.1 MVC SPA with React and Redux</Description>
    <RepositoryUrl>http://github.com/jonmcquade/aspnetcore-react-redux</RepositoryUrl>
    <PreserveCompilationContext>true</PreserveCompilationContext>
    <TypeScriptToolsVersion>2.8</TypeScriptToolsVersion>
    <OutputType>Exe</OutputType>
    <Version>2.1</Version>
  </PropertyGroup>

What am I missing to get this working?

Are there some machine configuration issues that I can check? Maybe environment variables? I've tried running a repair using the installers but this doesn't address the issue.

like image 736
Jammer Avatar asked May 20 '18 08:05

Jammer


People also ask

Where do I find global json?

json. The . NET SDK looks for a global. json file in the current working directory (which isn't necessarily the same as the project directory) or one of its parent directories.

How do I check my dotnet SDK version?

Checking the Version of Your .Open your project's source folder and, in the address bar, type "cmd" and press Enter. It will open the command prompt with the project path. Execute the following command: dotnet --version . It will display your project's current SDK version,i.e., 2.1.


2 Answers

The global.json specifies the SDK version of .NET Core that is being used to build your application. This has little to do with the .NET Core Runtime version that you want to run your application with.

Your application is a netcoreapp2.1, so you are running the .NET Core 2.1 Runtime. The earliest SDK Version for that is 2.1.300.

Since that is the latest .NET Core version, you actually don’t need to use a global.json at all: Just delete the file from your project and the tooling should use the latest version which is 2.1.300-rc1 on your machine.

like image 177
poke Avatar answered Oct 04 '22 01:10

poke


If you're running into this issue on OSX you can fix the issue thusly:

which dotnet

ls + the output from the previous command

You should now see something like: /usr/local/share/dotnet/dotnet

The directory that has your dotnet binary should also have a directory called sdk, so for the above example you can run ls /usr/local/share/dotnet/sdk, which should output a directory with your current version number. In my case that is 2.1.403 (there may be a better way to get the version number, but I was unable to run dotnet --version without specifying the correct sdk)

If I now open the global.json file in my app's root directory and change the sdk version to "2.1.403-osx-gs-x64", I should now be able to run dotnet command such as dotnet run from within my project.

like image 31
NM Pennypacker Avatar answered Oct 03 '22 23:10

NM Pennypacker