无法从UWP引用.NET Core库 [英] Cannot reference .NET Core library from UWP
问题描述
我有一个 .NET核心库有以下project.json:
{
版本:1.0.0- *,
依赖:{
NETStandard.Library:1.6.0
},
框架:{
netstandard1.6:{}
},
脚本:{
postcompile:[
DOTNET包--no -build --configuration释放,
XCOPY bin\\Release ..\\..\\lib\\ / Y
]
}
}
其中postcompile脚本创建一个的NuGet包哪些我添加为VS定制的饲料,以下这些说明。
这是因为我想要的从Windows通用应用程序,它不能以其他方式(还)引用它,根据的这个问题。
但当我尝试它,我得到这个消息:
包装乙太1.0.0不符合uap10兼容。 0(UAP,版本= V10.0)。
套餐乙太1.0.0支持:netstandard1.6(.NETStandard,版本V1.6 =)
一个或多个包不兼容不稳定型心绞痛,版本= V10.0。
这是它停止决策意识给我。根据这个,它应该工作的罚款netstandard> = 1.6。 0,而这位官员表说我需要针对netstandard< = 1.4.0,但是这并不能改变什么。更容易混淆的,如果我降级的两个 netstandard(依赖和目标框架),比方说,1.5的版本,我仍然得到这个确切的同样的错误,不指定任何我的文件1.6。
更新
中的UWP project.json看起来像这样
{
依赖:{
Microsoft.NETCore.UniversalWindowsPlatform:5.2.1
},
框架:{
uap10.0:{}
},
运行时间:{
win10臂:{},
win10臂-AOT: {}
win10-86:{}
win10-x86的AOT:{}
win10-64:{}
win10 -x64-AOT:{}
}
}
有人可以清理或者
- 如何引用从UWP的.Net核心库的全部或
- 什么是我的具体情况怎么回事?
答案
我解决它添加一个导入到UWP应用程序如下:
{
依赖:{
Microsoft.NETCore.UniversalWindowsPlatform:5.2.1
},
框架:{
uap10.0:{进口[netstandard1.6]}
},
运行时间:{
win10臂:{},
win10臂-AOT:{} ,
win10-86:{}
win10-x86的AOT:{}
win10-64:{}
win10-64 -aot:{}
}
}
您需要Microsoft.NETCore.UniversalWindowsPlatform升级到5.2.1
更新七月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臂:{},
win10-臂AOT:{}
win10-86:{}
win10-x86的AOT:{}
win10-64:{ }
win10-x64的AOT:{}
}
} -
创建一个新的dotnet核心库
- 构建库,并生成一个包的NuGet
- 我能够引用该.dll文件或包裹的NuGet。我的不要获取智能化的同时输入代码
- UWP建成并成功部署,但一旦我运行它,抛出一个异常
的
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
- How to reference .Net Core libraries from UWP at all or
- 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
- create a new UWP
- Upgrade to 5.2.2, which comes out on July, 14
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": {} } }
create a new dotnet core library
- build the library, and generate a nuget package
- I am able to reference the .dll file or the nuget package. And i Do get intelligent while typing code
- UWP is built and deployed successfully, but once i run it, an exception is thrown
这篇关于无法从UWP引用.NET Core库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!