【问题标题】:Trying to install EF Core with Portable Class Library targeting .Net 4.6.1尝试使用面向 .Net 4.6.1 的可移植类库安装 EF Core
【发布时间】:2016-05-02 12:47:24
【问题描述】:

这是我第一次使用 VS2015 试验 EF Core、ASP Net Core 和可移植类库。公平地说,我感到很沮丧。

我想创建一个可以安装 EntityFramework.Core 的库。这个库需要在 WPF 应用程序和 ASP NET Core Web 应用程序中使用——暂时忽略任何好的分层应用程序概念。我的想法是创建一个可移植类库。

使用我面向 .NET 4.6 和 ASP Net Core 的项目模板...

我得到一个项目,其中包含一个类和一个 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 包时...

...我得到以下输出:

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?如果是这样,我需要如何处理该项目?

我只是觉得我在网上兜圈子寻找解决方案。

更新 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 项目中。

更新 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 也会发生同样的情况。

公平地说,这完全令人沮丧。也许我今天在叫错树,或者只是在狂吠。

【问题讨论】:

  • 在atm遇到同样的问题
  • 嗨,这显然是 GitHub 上的一个未解决问题:github.com/aspnet/EntityFramework/issues/5176(破坏依赖关系)
  • 我只能说这是团队的不负责任。有一个 RC 甚至没有正确安装,甚至有很多问题,而且实际上已经 5 个月没有更新,这是完全不能接受的!负责任的事情是至少有一个实用路线图,同时要做什么,否则,他们应该从 Nuget 拉出这些 RC。上周我在常规 .NET 4.6 上安装了 EFCore,并且在安装(以及在荒谬的变通方法之后)然后运行它时遇到了很多重大问题,只是发现这些错误 已在 myget rc2 版本中修复。

标签: entity-framework portable-class-library entity-framework-core


【解决方案1】:

我不知道这将如何满足您的 Portable Class 需求,但对于常规的 .NET(4.6 或等),我发现了以下内容。 (见下面的咆哮)

所以我不知道这是否是“犹太洁食”,但这个来源现在有效:

添加nuget包源(Options - Package Sources - Add(加号)

如果您要为 SqlServer 安装,只需安装这个:

Microsoft.EntityFrameworkCore.SqlServer

或者选择另一个顶级依赖项,它将获取所有其他需要的依赖项。

*[开始咆哮] 那只是在 EF github 讨论中四处寻找。他们没有一个实用的描述来解释现在该做什么,这是完全不可原谅的。他们应该拉出“RC”1 版本,其中包含所有错误,其设计与他们现在正在研究的完全不同,并且已经超过 5 个月没有更新(!这是与'pre -release' 标记已选中!),完全来自 nuget。

让我补充一下:我喜欢这些家伙所做的一切,我喜欢新的东西,很多非常好的东西。但是我们不应该让一个所谓的仍然被标记为“RC”的版本挂了半年,因为它充满了已经在彻底重新设计的 rc2 版本中修复的错误,他们没有公示。 [/end-rant]*

【讨论】:

  • 我不能告诉你... EntityFramework.MicrosoftSqlServer 现在是 Microsoft.EntityFrameworkCore.SqlServer... 这是什么 myget.org。我只是喜欢工作。盒子外面。我不想买一辆车,然后发现我需要连接所有的电器。希望微软能把它整理好。顺便说一句,好咆哮
  • 我设置了一个新的包源,然后创建了一个新的 PCL 项目。它不会向其中添加 Microsoft.EntityFrameworkCore.SqlServer。那里有很多不兼容的软件包。 nuget 的 EF Core 安装在标准类库中。但是我想将我的“类库”添加到一个 aspnet 核心项目中——不管你信不信,我在引用 aspnet 核心项目中的类库时遇到了问题。所以我沿着这条路走。
【解决方案2】:

您是否尝试过将框架导入更改为:

"frameworks": {
   "netcoreapp1.0": {
     "imports": "portable-net451+win8"
   }
}

【讨论】:

    【解决方案3】:

    我创建了一个项目 Class Library Core 4.6 并在 project.json 中使用此代码

       {
          "dependencies": {
            "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0-rc2-final",
            "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0-rc2-final",
            "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview1-final",
            "Microsoft.NETCore.App": {
              "version": "1.0.0-rc2-3002702",
              "type": "platform"
            }
          },
    
          "tools": {
            "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
              "version": "1.0.0-preview1-final",
              "imports": "portable-net45+win8+dnxcore50"
            },
            "Microsoft.EntityFrameworkCore.Tools": {
              "version": "1.0.0-preview1-final",
              "imports": [
                "portable-net45+win8+dnxcore50",
                "portable-net45+win8"
              ]
            }
          },
    
          "frameworks": {
            "netcoreapp1.0": {
              "imports": [
                "dotnet5.6",
                "dnxcore50",
                "portable-net45+win8"
              ]
            }
          }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-09
      • 1970-01-01
      • 2016-11-05
      • 2017-09-11
      • 1970-01-01
      • 1970-01-01
      • 2016-10-29
      • 2018-09-03
      相关资源
      最近更新 更多