Entity Framework Core 1.0.1 add-migration

asp.net-core entity-framework-core

Question

Since EF Core migrated to Microsoft.EntityFrameworkCore.* (instead of EntityFramework.*), it seems that the recommended command line to add db migrations is back to add-migration from package manager.

ef core add migration documentation

However it seems there isn't a package anymore for commands and that the package installation of v 1.0.1 doesn't add any command.

The error message I'm getting when running Add-Migration is

Cannot execute this command because EntityFramework.Commands is not installed in the startup project 'project name'.

Did I miss something? Is there a new way to add the commands or so? Thanks for your help!

1
2
9/28/2016 3:34:36 PM

Accepted Answer

In order to use the Package Manager Console commands (e.g. Add-Migration) on .NET Core projects, your project.json will need to look something like this.

{
    "dependencies": {
        "Microsoft.EntityFrameworkCore.Sqlite": "1.0.1",
        "Microsoft.EntityFrameworkCore.Tools": {
            "version": "1.0.0-preview2-final",
            "type": "build"
        }
    },
    "tools": {
        "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
    }
}

The Microsoft.EntityFrameworkCore.Tools under dependencies ensures the PowerShell commands get registered. It's "type": "build" ensures they don't get published with your application. The Microsoft.EntityFrameworkCore.Tools under dependencies ensures the dotnet ef command gets registered (which is called by the PowerShell commands).

6
9/28/2016 8:27:42 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow