我有一个包含以下 project.json 的 .NET Core 库:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": { }
},
"scripts": {
"postcompile": [
"dotnet pack --no-build --configuration Release",
"xcopy bin\\Release ..\\..\\lib\\ /Y"
]
}
}
后编译脚本创建一个 nuget 包,我在 VS 中将其添加为自定义提要,遵循 these instructions . 这是因为我想从 Windows Universal App 引用它,根据 this question,这是不可能的(目前)。 . 但是当我尝试时,我收到了这条消息:
Package AEther 1.0.0 is not compatible with uap10.0 (UAP,Version=v10.0).
Package AEther 1.0.0 supports: netstandard1.6 (.NETStandard,Version=v1.6)
One or more packages are incompatible with UAP,Version=v10.0.
这就是它对我来说不再有意义的地方。根据this ,它应该适用于 netstandard >=1.6.0,而 this official table说我需要以 netstandard <=1.4.0 为目标,但这并没有改变任何东西。更令人困惑的是,如果我将 netstandard 的两个版本(依赖项和目标框架)降级到,比如说,1.5,我仍然会得到完全相同的错误,而无需在我的任何文件中指定 1.6。
更新 UWP project.json 看起来像这样
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.1"
},
"frameworks": {
"uap10.0": {}
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
谁能清理一下
- 如何完全从 UWP 引用 .Net Core 库或
- 我的具体情况是怎么回事?
回答
我通过向 UWP 应用添加导入解决了这个问题,如下所示:
{
"dependencies": {
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.1"
},
"frameworks": {
"uap10.0": { import [ "netstandard1.6" ] }
},
"runtimes": {
"win10-arm": {},
"win10-arm-aot": {},
"win10-x86": {},
"win10-x86-aot": {},
"win10-x64": {},
"win10-x64-aot": {}
}
}
最佳答案
您需要将 Microsoft.NETCore.UniversalWindowsPlatform 升级到 5.2.1
7 月 15 日更新
好的,这是我的结果
- 创建一个新的 UWP
- 升级到 5.2.2,将于 7 月 14 日发布
更新project.json,导入“netstandard1.6”
{ “依赖”:{ "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2", “测试”:“1.0.0” }, “构架”: { “uap10.0”:{ “进口”:[ “netstandard1.6” ] } }, “运行时”:{ “win10-arm”:{}, “win10-arm-aot”:{}, “win10-x86”:{}, “win10-x86-aot”:{}, “win10-x64”:{}, “win10-x64-aot”:{} } }
创建一个新的 dotnet 核心库
- 构建库,生成nuget包
- 我能够引用 .dll 文件或 nuget 包。我确实在输入代码时变得聪明
- UWP 已成功构建和部署,但一旦我运行它,就会抛出异常
关于c# - 无法从 UWP 引用 .NET Core 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38315273/