asp.net-core - ASP.Net 5类库包中的EntityFramework命令?

标签 asp.net-core .net-core entity-framework-core

我正在尝试开发我的第一个ASP.Net Web应用程序,在我的解决方案中,我有两个项目。一个Web ApplicationClass Library (Package)。在构建此应用程序的ASP.Net 4.5版本时,我将Entity Framework 6实体放入类库中,因此我在ASP.Net 5版本中进行了此操作。问题是,当我将EntityFramework.Commands安装到类库时,出现错误:

The dependency EntityFramework.Command 7.0.0-rc1-final in Project DBEntities does not support framework .NetPlatform, Version = 5.4



我对this SO question的理解是dotnet5.4是新的.Net 5,应该由EF7支持。

这是我的project.json文件:
{
  "version": "1.0.0-*",
  "description": "FFInfo.DAL Class Library",
  "authors": [ "Mathew" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
    "frameworks": {
        "dotnet5.4": {
            "dependencies": {
                "Microsoft.CSharp": "4.0.1-beta-23516",
                "System.Collections": "4.0.11-beta-23516",
                "System.Linq": "4.0.1-beta-23516",
                "System.Runtime": "4.0.21-beta-23516",
                "System.Threading": "4.0.11-beta-23516"
            }
        }
    },
    "dependencies": {
        "EntityFramework.Commands": "7.0.0-rc1-final",
        "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final"
    }
}

我安装了错误的软件包吗?EF7发生了太大变化以至于我建立了错误的类吗?还是我的json文件中丢失了某些内容?

编辑:
基于建议的新project.json文件
{
    "version": "1.0.0-*",
    "description": "FFInfo.DAL Class Library",
    "authors": [ "Mathew" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",
    "frameworks": {
        "dotnet5.4": {
            "dependencies": {
                "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*",
                "Microsoft.Dnx.Runtime": "1.0.0-*",
                "Microsoft.Extensions.CommandLineUtils.Sources": {
                    "version": "1.0.0-*",
                    "type": "build"
                },
                "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
                "System.Console": "4.0.0-*",
                "System.IO.FileSystem": "4.0.1-*"
            }
        },
        "netcore50": {
            "bin": {
                "assembly": "lib\\netcore50\\_._"
            }
        },
        "dependencies": {
            "EntityFramework.Commands": "7.0.0-rc1-final",
            "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final"
        }
    }
}

最佳答案

我想您出现问题的原因纯粹是技术性的。 The announcement声明将dnx451重命名为net451,将dnxcore50重命名为dotnet5.4,但建议仅将此类重命名用于类库(例如,您在NuGet上公开了此名称,以便与其他库共享)。如果我理解正确,那您将开发使用类库的应用程序,因此应使用dnxcore50而不是dotnet5.4。因此,您只需要将字符串“dotnet5.4”重命名为字符串"dnxcore50" in the file project.json`即可解决问题。

独立于上述建议,我想补充一下您的问题,为什么会出现关于EntityFramework.Command 7.0.0-rc1-final的错误。

我了解框架的重命名是迈向计划Microsoft的 future 更改的一步。另一方面,框架的所有名称将被解释为不同的名称。我建议您将https://www.nuget.org/packages/EntityFramework.Commands/7.0.0-rc1-final上的相关信息与https://www.nuget.org/packages/EntityFramework.MicrosoftSqlServer/7.0.0-rc1-final上的相应信息进行比较。 EntityFramework.MicrosoftSqlServer的依赖项(与dotnet5.4的使用没有关系)看起来像在图片上

enter image description here

我标记为负责dotnet5.4的部分。另一方面,EntityFramework.Commands的依赖关系如下图所示:

enter image description here

没有对应新名称dotnet5.4的“.NETPlatform 5.4”部分。

我想这是,是project.json EntityFramework.Commandsthe part中的错误:

"netcore50": {
  "bin": {
    "assembly": "lib\\netcore50\\_._"
  }
}

我想必须将各行中的netcore50更改为dotnet5.4才能正确支持新的框架名称dotnet5.4。应该将"netcore50"的内容替换为dnxcore50的副本(请参阅the lines):

"dotnet5.4": {
  "dependencies": {
    "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*",
    "Microsoft.Dnx.Runtime": "1.0.0-*",
    "Microsoft.Extensions.CommandLineUtils.Sources": {
      "version": "1.0.0-*",
      "type": "build"
    },
    "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
    "System.Console": "4.0.0-*",
    "System.IO.FileSystem": "4.0.1-*"
  }
}

事件可能会增加上面引用的dll的某些版本号,但在新的固定版本发布之前,您仍然无法使用EntityFramework.Commands下的"dotnet5.4"

更新:我向EntityFramework开发人员团队介绍了the issue。得到后,我将包括Microsoft对这个问题的答复。

关于asp.net-core - ASP.Net 5类库包中的EntityFramework命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34370874/

相关文章:

c# - INotifyPropertyChanged 未使用 Entity Framework Core 正确调用

asp.net - 如何配置 Entity Framework 以允许数据库为 PostgreSQL (npgsql) 生成 uuid?

c# - 在 .Net Core 3.0 项目中正确设置 ASP.Net Core 授权和身份验证

asp.net - .Net 核心应用程序无法通过 FTP 上传,托管在 IIS 上

c# - EF Core 已跟踪具有相同 id 的实体

.net-core - Entity Framework 核心 : How to get the Connection from the DbContext?

c# - blazor 的事件回调

asp.net - 对 https ://login. microsoftonline.com 上的 XMLHttpRequest 的访问已被 CORS 策略阻止

c# - 如何永久为所有查询请求启用 Apollo Tracing with Hot Chocolate?

c# - BackgroundService 未关闭,stoppedToken 从未使用 .net 核心通用主机设置