首页 > 解决方案 > 启动新的 react-native 项目时找不到 .Net 核心

问题描述

我按照本教程为 windows 项目创建了新的 react-native 。我在 VS Code 中工作,但是要运行该应用程序,我必须安装 Visual Studio Community,否则它在启动时给了我错误:

error Unable to find vswhere

在我使用本教程中的所有选项安装 Visual Studio 后,错误变为:

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.

我尝试寻找解决方案,推荐的是这个。所以我检查了我的命令行。运行dotnet --list-sdks后只有一个版本:

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

global.json我在我的项目中使用以下文本创建了文件:

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

但是在我运行npx react-native run-windows命令后,出现以下错误:

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

我不明白为什么即使dotnet --list-sdks工作正常也找不到它?这是我的项目的屏幕截图: 在此处输入图像描述

标签: .netruntime-errorreact-native-windows

解决方案


请改为在https://github.com/microsoft/react-native-windows上发帖:)

RNW 不支持 .net 核心。对于托管 rnw 应用,仅支持“用于 UWP 应用的 .net 框架”。为确保您安装了它,请遵循文档的入门页面中描述的 rnw-dependencies 脚本。


更新:我重新阅读了你的问题,我现在更好地理解了。这是特定于 codegen 项目的,这可能是我们的错误。我已经提交了一个问题让我们跟踪它:https ://github.com/microsoft/react-native-windows/issues/6201


推荐阅读