Add-Migration command for Entity Framework 7 not working for ASP.NET 5 class library

asp.net-core c# entity-framework-core

Question

I created an ASP.NET 5 class library with the following dependencies

"EntityFramework.Core": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"EntityFramework.Commands": "7.0.0-rc1-final"

I created my model and DatabaseContext classes. Now I want to add a migration so that I can create the database. By calling

dnx ef Add-Migration InitialMigration

from the commandline which is giving me the following error message

System.InvalidOperationException: The current runtime target framework is not compatible with 'Yugasat.Test'. Current runtime target framework: 'DNX,Version=v4.5.1 (dnx451)' Version:
1.0.0-rc1-16231 Type: Clr Architecture: x86 OS Name: Windows OS Version: 10.0 Runtime Id: win10-x86

Please make sure the runtime matches a framework specified in project.json at Microsoft.Dnx.ApplicationHost.DefaultHost.GetEntryPoint(String applicationName) at Microsoft.Dnx.ApplicationHost.Program.ExecuteMain(DefaultHost host, String applicationName, String[] args) at Microsoft.Dnx.ApplicationHost.Program.Main(String[] args) --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at Microsoft.Dnx.Runtime.Common.EntryPointExecutor.Execute(Assembly 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)

As far as I can see from the error message my dnx version is 4.5.1 and the framework in my projects.json file is set to 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"
   }
}

Accepted Answer

"frameworks": {
    "net451": {}
}

You need to use dnx451 here, not net451. Then, the current runtime target framework (which is DNX,Version=v4.5.1 (dnx451)) will pick it up correctly.

Also note that the correct command is dnx ef migrations add InitialMigration; I’m not sure if the Add-Migration works.



Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why