c# - 无法从 UWP 引用 .NET Core 库

标签 c# .net nuget uwp .net-core

我有一个包含以下 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": {}
  }
}

谁能清理一下

  1. 如何完全从 UWP 引用 .Net Core 库或
  2. 我的具体情况是怎么回事?

回答

我通过向 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 日更新

好的,这是我的结果

  1. 创建一个新的 UWP
  2. 升级到 5.2.2,将于 7 月 14 日发布
  3. 更新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”:{} } }

  4. 创建一个新的 dotnet 核心库

  5. 构建库,生成nuget包
  6. 我能够引用 .dll 文件或 nuget 包。我确实在输入代码时变得聪明
  7. UWP 已成功构建和部署,但一旦我运行它,就会抛出异常 enter image description here

关于c# - 无法从 UWP 引用 .NET Core 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38315273/

相关文章:

c# - WCF RESTful 服务的 Java 和其他客户端

.net - Anycpu nuget 包需要 32 位或 64 位包

c# - 从 C# 到 Objective C 会有多大的飞跃

c# - xamarin 选择器控件 selectedindexchange 事件仅在完成选择项目时引发

c# - 将 vb6 类型转换为 VB.net 或 C# 结构

c# - 使用 Action<T> 创建任务

c# - c# 中的运动检测和对象提取?

c# - 使用 Xamarin 和 Microsoft 语音服务 API 执行实时连续语音识别

c# - mono-repo 中包的独立版本控制

c# - 如何创建依赖于 "targets projects"包的包?