Can't find .Net core when starting a new react-native project

632 views Asked by At

I created new react-native for windows project following this tutorial. I work in VS Code, but for the app to run I had to install Visual Studio Community, otherwise it gave me error on start:

error Unable to find vswhere

After I installed Visual Studio with all options from this tutorial, error changed to:

Failed to restore the NuGet packages: Error: 
C:\Users\Alyona\Documents\Programming\accounting_app\node_modules\react-native- 
windows\Microsoft.ReactNative.Managed.CodeGen\Microsoft.ReactNative.Managed.CodeGen.csproj : error : 
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 tried searching for solutions, and the one that was recommended was this. So I checked my command line. After running dotnet --list-sdks there was just one version:

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

I created global.json file in my project with following text:

{
  "sdk": {
    "version": "3.1.402"
  }
}

But after I ran npx react-native run-windows command I got following error:

Failed to restore the NuGet packages: Error: 
C:\Users\Alyona\Documents\Programming\accounting_app\node_modules\react-native- 
windows\Microsoft.ReactNative.Managed.CodeGen\Microsoft.ReactNative.Managed.CodeGen.csproj : error : 
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.

C:\Users\Alyona\Documents\Programming\accounting_app\node_modules\react-native- 
windows\Microsoft.ReactNative.Managed.CodeGen\Microsoft.ReactNative.Managed.CodeGen.csproj : error 
MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.

A compatible installed .NET Core SDK for global.json version [3.1.402] from 
[C:\Users\Alyona\Documents\Programming\accounting_app\global.json] was not found

I can't understand why it can't find it even though dotnet --list-sdks works fine? Here's the screenshot of my project: enter image description here

1

There are 1 answers

1
Alexander Sklar - MSFT On

Please post on https://github.com/microsoft/react-native-windows instead :)

RNW doesn't support .net core. For managed rnw apps, only the ".net framework for UWP apps" is supported. To make sure you get it installed please follow the rnw-dependencies script that's described in the getting started page in the docs.


update: I re-read your question and I understand it better now. This is specific to the codegen project, this might be a bug on our end. I've filed an issue for us to track it: https://github.com/microsoft/react-native-windows/issues/6201