我创建了一个带有以下依赖项的ASP.NET 5类库
"EntityFramework.Core": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"EntityFramework.Commands": "7.0.0-rc1-final"
我创建了我的模型和DatabaseContext类。现在我想添加一个迁移,以便我可以创建数据库。致电
dnx ef Add-Migration InitialMigration
从命令行给出了以下错误消息
System.InvalidOperationException:当前运行时目标框架 与'Yugasat.Test'不兼容。当前运行时目标 框架:'DNX,Version = v4.5.1(dnx451)'版本:
1.0.0-rc1-16231类型:Clr架构:x86 OS名称:Windows OS版本:10.0运行时ID:win10-x86请确保运行时与指定的框架匹配 project.json at Microsoft.Dnx.ApplicationHost.DefaultHost.GetEntryPoint(字符串 applicationName)at Microsoft.Dnx.ApplicationHost.Program.ExecuteMain(DefaultHost主机, String applicationName,String [] args)at Microsoft.Dnx.ApplicationHost.Program.Main(String [] args) ---从抛出异常的先前位置开始的堆栈跟踪结束--- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(大会 assembly,String [] args,IServiceProvider serviceProvider)at Microsoft.Dnx.Host.Bootstrapper.RunAsync(List`1 args, IRuntimeEnvironment env,String appBase,FrameworkName targetFramework)at Microsoft.Dnx.Host.RuntimeBootstrapper.ExecuteAsync(String [] args, BootstrapperContext bootstrapperContext)at Microsoft.Dnx.Host.RuntimeBootstrapper.Execute(String [] args, BootstrapperContext bootstrapperContext)
据我从错误消息中可以看到,我的dnx版本是4.5.1,而我的projects.json文件中的框架设置为4.5.1
{
"version": "1.0.0-*",
"description": "Yugasat.Test Class Library",
"authors": [ "AndreL" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"frameworks": {
"net451": {
}
},
"dependencies": {
"EntityFramework.Core": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"EntityFramework.Commands": "7.0.0-rc1-final"
},
"commands": {
"ef": "EntityFramework.Commands"
}
}
答案 0 :(得分:3)
"frameworks": {
"net451": {}
}
您需要在此使用dnx451
,而不是net451
。然后,当前运行时目标框架(DNX,Version=v4.5.1 (dnx451)
)将正确地选择它。
另请注意,正确的命令是dnx ef migrations add InitialMigration
;我不确定Add-Migration
是否有效。