无法从 UWP 引用 .NET Core 库
Cannot reference .NET Core library from UWP
我有一个 .NET Core 库,其中 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"
]
}
}
其中后编译脚本创建了一个 nuget 包,我在 these instructions 之后将其添加为 VS 中的自定义提要。
这是因为我想 从 Windows 通用应用程序 引用它,根据 ,这是不可能的(目前)。
但是当我尝试时,我收到这条消息:
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.
这就是它对我来说不再有意义的地方。根据 , it should work fine for netstandard >=1.6.0, while this official table 的说法,我需要以 netstandard <=1.4.0 为目标,但这并没有改变任何东西。更令人困惑的是,如果我将 netstandard(依赖项和目标框架)的 both 版本降级到,比如说,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
- 升级到 7 月 14 日发布的 5.2.2
更新project.json,导入"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": {}
}
}
创建新的 dotnet 核心库
- 构建库,并生成 nuget 包
- 我可以引用 .dll 文件或 nuget 包。我 Do 在输入代码时变得聪明
- UWP 已成功构建和部署,但是一旦我 运行 它,就会抛出异常
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.
Universal Windows Platform maps to netstandard1.4 - 既不是 1.6 也不是 1.5。因此,您的库(我假设称为 AEther
)比您的 UWP 应用程序具有更高的要求。
- How to reference .Net Core libraries from UWP at all or
如 所述,Visual Studio 尚不支持此功能。
我只能猜测这与CLI的支持有关,即an open issue。从今天开始,它预计将在 Microsoft.NETCore.UniversalWindowsPlatform
元包的 5.3 版中得到修复 - 虽然之前预计它会在 5.2.2 中得到修复。
- What is going on in my specific case?
NuGet 告诉您您的包仅支持 netstandard1.6
target framework 但不支持 uap10.0
。事实上,如果您解压缩 .nupkg
,您会在 lib\netstandard1.6
下找到您的 DLL。
因为 dotnet pack automatically creates the .nuspec
from your project.json
so you'll need to fix it with the proper framework (eg. netstandard1.4
). It'll probably be easier compiling for different frameworks, for instance Portable profiles compatible with .NET Platform Standard.
我有一个 .NET Core 库,其中 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"
]
}
}
其中后编译脚本创建了一个 nuget 包,我在 these instructions 之后将其添加为 VS 中的自定义提要。
这是因为我想 从 Windows 通用应用程序 引用它,根据
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.
这就是它对我来说不再有意义的地方。根据
更新 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
- 升级到 7 月 14 日发布的 5.2.2
更新project.json,导入"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": {} } }
创建新的 dotnet 核心库
- 构建库,并生成 nuget 包
- 我可以引用 .dll 文件或 nuget 包。我 Do 在输入代码时变得聪明
- UWP 已成功构建和部署,但是一旦我 运行 它,就会抛出异常
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.
Universal Windows Platform maps to netstandard1.4 - 既不是 1.6 也不是 1.5。因此,您的库(我假设称为 AEther
)比您的 UWP 应用程序具有更高的要求。
- How to reference .Net Core libraries from UWP at all or
如
我只能猜测这与CLI的支持有关,即an open issue。从今天开始,它预计将在 Microsoft.NETCore.UniversalWindowsPlatform
元包的 5.3 版中得到修复 - 虽然之前预计它会在 5.2.2 中得到修复。
- What is going on in my specific case?
NuGet 告诉您您的包仅支持 netstandard1.6
target framework 但不支持 uap10.0
。事实上,如果您解压缩 .nupkg
,您会在 lib\netstandard1.6
下找到您的 DLL。
因为 dotnet pack automatically creates the .nuspec
from your project.json
so you'll need to fix it with the proper framework (eg. netstandard1.4
). It'll probably be easier compiling for different frameworks, for instance Portable profiles compatible with .NET Platform Standard.