当前运行时目标框架与项目不兼容

时间:2015-11-12 06:41:29

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

我在将Entity Framework 7添加到我的Asp.Net 5项目后尝试执行初始迁移。我正在关注documentation

在我指定的project.json中:

  "commands": {
    "web": "Microsoft.AspNet.Server.Kestrel",
    "ef": "EntityFramework.Commands"
  },

  "frameworks": {
    "dnxcore50": { }
  }

我试图通过命令提示符在项目目录中执行以下命令:

dnx ef migrations add MyFirstMigration

但是我收到以下错误:

  

System.InvalidOperationException:当前运行时目标框架   与ProjectName不兼容。当前的运行时目标   框架:' DNX,版本= v 4.5.1(dnx451)请确保运行时   匹配project.json中指定的框架。

奇怪的是,我的project.json肯定会定位dnxcore50。我还检查了global.json

{
  "projects": [ "src", "test" ],
  "sdk": {
    "version": "1.0.0-beta8",
    "architecture": "x86",
    "runtime": "coreclr"
  }
}

我的包依赖项都引用了beta8:

  "dependencies": {
    "EntityFramework.Commands": "7.0.0-beta8",
    "EntityFramework.Core": "7.0.0-beta8",
    "EntityFramework.SqlServer": "7.0.0-beta8",
    "Hl7.Fhir.DSTU2": "0.90.2",
    "Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta8",
    "Microsoft.AspNet.Authentication.OpenIdConnect": "1.0.0-beta8",
    "Microsoft.AspNet.Diagnostics": "1.0.0-beta8",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-beta8",
    "Microsoft.AspNet.Mvc": "6.0.0-beta8",
    "Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta8",
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-beta8",
    "Microsoft.AspNet.StaticFiles": "1.0.0-beta8",
    "Microsoft.AspNet.Tooling.Razor": "1.0.0-beta8",
    "Microsoft.Dnx.Runtime": "1.0.0-beta8",
    "Microsoft.Framework.Configuration.Json": "1.0.0-beta8",
    "Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta8",
    "Microsoft.Framework.Logging": "1.0.0-beta8",
    "Microsoft.Framework.Logging.Console": "1.0.0-beta8",
    "Microsoft.Framework.Logging.Debug": "1.0.0-beta8",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta8"
  }

1 个答案:

答案 0 :(得分:17)

您需要将 "frameworks": { "dnxcore50": { }, "dnx451": { } } 添加到项目支持的框架中,或者切换到.NET Core版本。

dnvm install latest -r coreclr

或运行:

dnvm use default -r coreclr

{{1}}