无法从 UWP 引用 .NET Core 库 [英] Cannot reference .NET Core library from UWP

查看:34
本文介绍了无法从 UWP 引用 .NET Core 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有以下 project.json 的 .NET Core 库:

<代码>{"版本": "1.0.0-*",依赖关系":{"NETStandard.Library": "1.6.0"},构架": {netstandard1.6":{}},脚本":{后编译":["dotnet pack --no-build --configuration Release","xcopy bin\Release ..\..\lib\/Y"]}}

其中后编译脚本创建了一个 nuget 包,我将其添加为 VS 中的自定义提要,遵循

I have a .NET Core library with the following project.json:

{
  "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"
    ]
  }
}

where the postcompile script creates a nuget package which I added as a custom feed in VS, following these instructions. This is because I want to reference it from a Windows Universal App, which cannot be otherwise (yet), according to this question. But when I try it, I get this message:

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 is where it stops making sense to me. According to this, it should work fine for netstandard >=1.6.0, while this official table says I need to target netstandard <=1.4.0, but that doesn't change anything. More confusingly, if I downgrade both versions of netstandard (the dependency and the target framework) to, say, 1.5, I still get this exact same error without specifying 1.6 in any of my files.

Update The UWP project.json looks like this

{
  "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": {}
  }
}

Can someone clear up either

  1. How to reference .Net Core libraries from UWP at all or
  2. What is going on in my specific case?

ANSWER

I solved it adding an import to the UWP app as follows:

{
  "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": {}
  }
}

解决方案

you need to upgrade Microsoft.NETCore.UniversalWindowsPlatform to 5.2.1


Update on July, 15

Ok, here is my result

  1. create a new UWP
  2. Upgrade to 5.2.2, which comes out on July, 14
  3. update project.json, import "netstandard1.6"

    { "dependencies": { "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2", "Test": "1.0.0" }, "frameworks": { "uap10.0": { "imports": [ "netstandard1.6" ] } }, "runtimes": { "win10-arm": {}, "win10-arm-aot": {}, "win10-x86": {}, "win10-x86-aot": {}, "win10-x64": {}, "win10-x64-aot": {} } }

  4. create a new dotnet core library

  5. build the library, and generate a nuget package
  6. I am able to reference the .dll file or the nuget package. And i Do get intelligent while typing code
  7. UWP is built and deployed successfully, but once i run it, an exception is thrown

这篇关于无法从 UWP 引用 .NET Core 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆