这是我第一次使用 VS2015 尝试 EF Core、ASP Net Core 和可移植类库。公平地说我很沮丧。
我想创建一个可以安装 EntityFramework.Core 的库。该库需要在 WPF 应用程序和 ASP NET Core Web 应用程序中使用 - 现在忽略任何好的分层应用程序概念。我的想法是创建一个可移植类库。
使用我针对 .NET 4.6 和 ASP Net Core 的项目模板...
![Targets](https://i.stack.imgur.com/0kqJN.png)
我得到一个带有类和 project.json 文件的项目,如下所示:
{
"supports": {
"net46.app": {},
"dnxcore50.app": {}
},
"dependencies": {
"Microsoft.NETCore": "5.0.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.0"
},
"frameworks": {
"dotnet": {
"imports": "portable-net452"
}
}
}
现在,当我从 nuget 安装 EntityFramework.Core 包时...
![Install EF Core Nuget](https://i.stack.imgur.com/EPRHl.png)
...我得到以下输出:
Restoring packages for 'Acme.PCLEFClassLib'.
Restoring packages for K:\TFS\TestApps\Projects\DotNetCore\Acme.PCL1\Acme.PCL1\project.json...
Detected package downgrade: System.Reflection from 4.1.0-beta-23225 to 4.0.10
Acme.PCLEFClassLib (>= 1.0.0) -> EntityFramework.Core (>= 7.0.0-rc1-final) -> Microsoft.Extensions.DependencyInjection.Abstractions (>= 1.0.0-rc1-final) -> System.Reflection (>= 4.1.0-beta-23225)
Acme.PCLEFClassLib (>= 1.0.0) -> EntityFramework.Core (>= 7.0.0-rc1-final) -> System.Reflection (>= 4.0.10)
Detected package downgrade: System.Reflection from 4.1.0-beta-23225 to 4.0.10
Acme.PCLEFClassLib (>= 1.0.0) -> EntityFramework.Core (>= 7.0.0-rc1-final) -> Microsoft.Extensions.Logging.Abstractions (>= 1.0.0-rc1-final) -> System.Reflection (>= 4.1.0-beta-23225)
Acme.PCLEFClassLib (>= 1.0.0) -> EntityFramework.Core (>= 7.0.0-rc1-final) -> System.Reflection (>= 4.0.10)
Version conflict detected for System.Collections.
Acme.PCLEFClassLib (>= 1.0.0) -> EntityFramework.Core (>= 7.0.0-rc1-final) -> System.Collections (>= 4.0.11-beta-23516)
Acme.PCLEFClassLib (>= 1.0.0) -> Microsoft.NETCore.Portable.Compatibility (>= 1.0.0) -> Microsoft.NETCore.Runtime (>= 1.0.0) -> Microsoft.NETCore.Runtime.CoreCLR-x86 (>= 1.0.0) -> System.Collections (= 4.0.10).
EntityFramework.Core 7.0.0-rc1-final is not compatible with .NETPlatform,Version=v5.0.
Some packages are not compatible with .NETPlatform,Version=v5.0.
Ix-Async 1.2.5 is not compatible with DNXCore,Version=v5.0.
Remotion.Linq 2.0.1 is not compatible with DNXCore,Version=v5.0.
Some packages are not compatible with DNXCore,Version=v5.0.
Ix-Async 1.2.5 is not compatible with DNXCore,Version=v5.0 (win7-x86).
Remotion.Linq 2.0.1 is not compatible with DNXCore,Version=v5.0 (win7-x86).
Some packages are not compatible with DNXCore,Version=v5.0 (win7-x86).
Ix-Async 1.2.5 is not compatible with DNXCore,Version=v5.0 (win7-x64).
Remotion.Linq 2.0.1 is not compatible with DNXCore,Version=v5.0 (win7-x64).
Some packages are not compatible with DNXCore,Version=v5.0 (win7-x64).
Package restore failed for 'Acme.PCLEFClassLib'.
Package restore failed. Rolling back package changes for 'Acme.PCLEFClassLib'.
========== Finished ==========
是否真的可以将 EF Core 安装在可移植类库中?如果是这样,我需要对这个项目做什么?
我只是觉得我在网上寻找解决方案。
UPDATE 1
尝试在我的 PCL 中安装 EntityFramework.MicrosoftSqlServer。
鉴于在创建标准 ASP Net Core 项目时安装了 EntityFramework.MicrosoftSqlServer - 该项目使用 dnxcore50 框架。如果我在 PCL 中做类似的事情,为什么会抱怨:
EntityFramework.MicrosoftSqlServer 7.0.0-rc1-final is not compatible with .NETPlatform,Version=v5.0.
如果是这样的话,那么它为什么会安装到 ASP NET Core 项目中呢?
UPDATE 2
我创建了一个针对 .NET 4.5.1 的新 PCL。然后我通过 Nuget 将 EntityFramework.MicrosoftSqlServer 7.0.0-rc1-final 安装到其中,安装没有问题。虽然我现在不能重复这一点。我刚刚使用面向 ASP NET Core 和 .NET 4.5.1 的 PCL 库项目创建了一个单独的解决方案。现在输出以下内容:
Attempting to gather dependency information for package 'EntityFramework.MicrosoftSqlServer.7.0.0-rc1-final' with respect to project 'AnotherPCLEFFUP', targeting '.NETPortable,Version=v4.5,Profile=Profile75'
Attempting to resolve dependencies for package 'EntityFramework.MicrosoftSqlServer.7.0.0-rc1-final' with DependencyBehavior 'Lowest'
Resolving actions to install package 'EntityFramework.MicrosoftSqlServer.7.0.0-rc1-final'
Resolved actions to install package 'EntityFramework.MicrosoftSqlServer.7.0.0-rc1-final'
Install failed. Rolling back...
Package 'EntityFramework.MicrosoftSqlServer.7.0.0-rc1-final' does not exist in project 'AnotherPCLEFFUP'
Package 'EntityFramework.MicrosoftSqlServer.7.0.0-rc1-final' does not exist in folder 'K:\TFS\TestApps\Projects\DotNetCore\AnotherPCLEFFUP\packages'
Invalid portable frameworks.
安装 EntityFramework.Core.7.0.0-rc1-final 也会发生同样的情况。
公平地说,这真是令人沮丧。也许我今天叫错了树或者只是发疯了。