为什么这个 .NET Core 包与我的 PCL 不兼容?
Why isn't this .NET Core package compatible with my PCL?
我有一个针对以下平台的 PCL:
- .NET Framework 4.5
- Windows 8
- Windows Phone 8.1
我还有另一个包(称为 Enu),基于 .NET Core 和 project.json
,我想在这个 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)
,似乎也有问题(related post) installing on my PCL. The strange thing is, while it claims to be incompatible with my library, it supports all of the target platforms I do,所以我不看看为什么会这样。
TL;DR: NuGet 不允许在 PCL 上安装 .NET Core 包,因为它认为它们不兼容。经过调查,我发现问题的根源是包的依赖项与 PCL 不兼容,即使 it supports all of the platforms 我的 PCL 不兼容。为什么会这样?
这是 .NET Core 包的 project.json 文件,我做错了什么吗?
在您的 project.json 中定位 dotnet
将不包括 Windows 8 和 Windows Phone 8.1。尝试在目标框架中添加 netcore45
和 wpa81
。
不支持您尝试的内容,因为您正在创建一个 PCL,它只允许 .NET 4.5、Windows 8 和 Windows Phone 8.1 并且您正在尝试添加对此 PCL 的引用,这是您允许的 API 的超集。这会产生冲突,因为 Enu 包可能使用在 .NET 4.5、Windows 8 and/or Windows Phone 8.1 上不可用的 APIs。
要使用 .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".
好吧,经过三个星期的努力,我终于(终于)解决了这个问题。这是我的新作品 project.json
:
{
...
"frameworks": {
"dotnet": {
"dependencies": {
"System.Runtime": "4.0.20"
}
},
".NETPortable,Version=v4.5,Profile=Profile111": {
"frameworkAssemblies": {
"System.Runtime": ""
}
}
}
}
感谢 Mark 和 these guys 给我的想法。
我有一个针对以下平台的 PCL:
- .NET Framework 4.5
- Windows 8
- Windows Phone 8.1
我还有另一个包(称为 Enu),基于 .NET Core 和 project.json
,我想在这个 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)
,似乎也有问题(related post) installing on my PCL. The strange thing is, while it claims to be incompatible with my library, it supports all of the target platforms I do,所以我不看看为什么会这样。
TL;DR: NuGet 不允许在 PCL 上安装 .NET Core 包,因为它认为它们不兼容。经过调查,我发现问题的根源是包的依赖项与 PCL 不兼容,即使 it supports all of the platforms 我的 PCL 不兼容。为什么会这样?
这是 .NET Core 包的 project.json 文件,我做错了什么吗?
在您的 project.json 中定位 dotnet
将不包括 Windows 8 和 Windows Phone 8.1。尝试在目标框架中添加 netcore45
和 wpa81
。
不支持您尝试的内容,因为您正在创建一个 PCL,它只允许 .NET 4.5、Windows 8 和 Windows Phone 8.1 并且您正在尝试添加对此 PCL 的引用,这是您允许的 API 的超集。这会产生冲突,因为 Enu 包可能使用在 .NET 4.5、Windows 8 and/or Windows Phone 8.1 上不可用的 APIs。
要使用 .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".
好吧,经过三个星期的努力,我终于(终于)解决了这个问题。这是我的新作品 project.json
:
{
...
"frameworks": {
"dotnet": {
"dependencies": {
"System.Runtime": "4.0.20"
}
},
".NETPortable,Version=v4.5,Profile=Profile111": {
"frameworkAssemblies": {
"System.Runtime": ""
}
}
}
}
感谢 Mark 和 these guys 给我的想法。