我有一个针对以下平台的PCL:
我还有另一个基于.NET Core和project.json
的软件包(名为 Enu ),我想在这个PCL中使用它。我的问题是,当我尝试将.NET Core软件包安装到我的PCL中时,收到一条错误消息,指出PCL与软件包不兼容。
PM> Install-Package Enu
# lots of output...
Install failed. Rolling back...
Package 'Enu 4.4.0' does not exist in project 'PclDummy'
Package 'Enu 4.4.0' does not exist in folder 'C:\Users\James\Documents\Visual Studio 2015\Projects\PclDummy\packages'
Install-Package : Could not install package 'Enu 4.4.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile111', but the package does not contain
any assembly references or content files that are compatible with that framework. For more information, contact the package author.
在深入研究这个问题后,我发现Enu依赖的软件包,特别是System.Runtime (v4.0.0)
,似乎也在我的PCL上安装了问题(related post)。奇怪的是,虽然它声称与我的图书馆不兼容,但supports all of the target platforms I do,所以我不明白为什么会这样。
TL; DR: NuGet不允许在PCL上安装.NET Core软件包,因为它认为它们不兼容。在调查之后,我发现问题的根源是包的依赖性与PCL不兼容,即使我的PCL it supports all of the platforms。为什么会这样?
这里是.NET Core软件包的project.json文件,我做错了吗?
答案 0 :(得分:5)
您正在尝试的内容不受支持,因为您正在创建一个仅允许.NET 4.5,Windows 8和Windows Phone 8.1的公共子集的PCL,并且您正在尝试添加对此PCL的引用,这是您允许的API的超集。这会产生冲突,因为Enu包可能使用.NET 4.5,Windows 8和/或Windows Phone 8.1上不可用的API。
要使用.NET Core库,您必须创建.NET 4.5库或使用 Enu 库的替代品,该库本身就是使用相同的PCL(.NET 4.5,Windows 8) ,Windows Phone 8.1)或.NET API的较小子集(.NET 4.5,Windows 8,Windows Phone 8.1和Windows Phone 8 Silverlight)。
编辑:看看你的NuGet软件包显示,你有一个面向.NET 4.5,Windows 8和Windows Phone 8.1的库,但你有适用于所有平台的不同程序集,但你需要使用它在PCL中是一个可以在所有平台上使用的组件。 NuGet平台标识符为“portable-net45 + win + wpa81”。答案 1 :(得分:2)
在project.json中定位dotnet
将不包括Windows 8和Windows Phone 8.1。尝试在目标框架中添加netcore45
和wpa81
。
答案 2 :(得分:2)
好吧,所以经过三个星期的努力,我终于(最终)解决了这个问题。这是我的新工作project.json
:
{
...
"frameworks": {
"dotnet": {
"dependencies": {
"System.Runtime": "4.0.20"
}
},
".NETPortable,Version=v4.5,Profile=Profile111": {
"frameworkAssemblies": {
"System.Runtime": ""
}
}
}
}
感谢Mark给我的想法以及these guys的任何人。