您的 project.json 没有将 'win10' 列为目标运行时

Your project.json doesn't list 'win10' as a targeted runtime

我讨厌重新发布,但我认为发布到 MSDN forum 是正确的做法,因为看起来没有多少人使用 HTML/JavaScript 开发 UWP 应用程序,但是,因为我有完全没有答案,我正在向伟大的 SO 社区寻求帮助。

问题:
我在 HTML/JavaScript 中有一个非常简单的 UAP 应用程序,它引用了一个 Windows 运行时组件,该组件引用了一个 Class 库。

我需要在任一台 PC and/or 手机上投射到 运行,所以我需要用 Any CPU 编译它。问题是每当我想编译我的应用程序时,我都会收到以下错误:

Your project.json doesn't list 'win10' as a targeted runtime. You should add '"win10": { }' inside your "runtimes" section in your project.json, and then re-run NuGet restore.

而且如果我在 运行 次下添加普通的 win10 条目,我会遇到许多其他错误。这就是我的 project.json 的样子:

{
"dependencies": {
    "Microsoft.NETCore.UniversalWindowsPlatform": "5.0.0"
},
"frameworks": {
    "uap10.0": { }
},
"runtimes": {
    "win10-arm": { },
    "win10-arm-aot": { },
    "win10-x86": { },
    "win10-x86-aot": { },
    "win10-x64": { },
    "win10-x64-aot": { }
}
}

此外,如果有人有兴趣查看,还有一个最小的复现 here

我有类似的设置和完全相同的问题。我目前的解决方法是在桌面上测试时将编译器设置为 x86,在移动设备上测试时更改为 ARM。远非最佳,但如果你想出更好的办法,我很乐意听到你的回音。

根据 this SO post,UWP/C# 个应用不支持 AnyCPU。

In addition to making sure you test with .NET Native compilation, you may also notice that the AnyCPU build configuration has disappeared. With .NET Native brought into the mix, AnyCPU is no longer a valid build configuration because native compilation is architecture dependent. An additional consequence of this is that when you package your application, you should select all three architecture configurations (x86, x64 and ARM) to make sure your application is applicable to as many devices as possible.

来源:.NET Native – What it means for Universal Windows Platform (UWP) developers

AnyCPU 不再是托管 (C#/VB) UWP 应用程序的有效配置。这是因为 UWP 应用程序的所有托管代码(exe 或 dll)都是使用 .NET Native 工具链编译的,以构建特定于体系结构的二进制文件。因此,如果您在 HTML/JS UWP 应用程序中使用托管 WinRT 组件,您还需要根据要部署到的设备在应用程序项目中设置特定架构,即 x86 用于桌面,ARM 用于 Phone 设备.

要修复此错误: 在项目页面上;构建选项卡:平台目标 = "value in dropdown, ie x86,x64,ARM" 用于本地运行。 如果发布... 右键单击项目,select Store|Create App Packages... 在 Select 和配置包 页面上,取消选中 Neutral (Any CPU),选中 x86、x64、ARM。