Add-Migration fails because EntityFrameworkCore.Tools is not installed

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

Question

I want to create a console application with EF Core by following this tutorial: http://ef.readthedocs.io/en/latest/platforms/full-dotnet/new-db.html.

My problem is, I cannot execute the statement

Add-Migration 

as described in the tutorials. It shows me:

PM> Add-Migration MyFirstMigration
Cannot execute this command because 'Microsoft.EntityFrameworkCore.Tools' is not installed in project 'src\AppEf'. Add 'Microsoft.EntityFrameworkCore.Tools' to the 'tools' section in project.json. See http://go.microsoft.com/fwlink/?LinkId=798221 for more details.

All added assemblies:

enter image description here

What is wrong?

Update

The statement dotnet restore works and dotnet-ef --help does not work at all.
enter image description here

And you can see, the statement is execute in project folder.

1
3
7/12/2016 2:13:50 PM

Popular Answer

As a few people mentioned in the comments, Microsoft.EntityFrameworkCore.Tools needs to be added to the tools section of project.json.

I've tested this project.json with the latest (July 2016) versions of EF Core and the tooling packages, and it works:

{
    "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.Design": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0"
    }
  },
  "frameworks": {
    "netcoreapp1.0": {}
  },
  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
  },
  "version": "1.0.0-*"
}

To use it, execute these commands from inside the project folder:

λ dotnet restore
log  : Restore completed in 2810ms.

λ dotnet ef --help
Compiling EfCoreTester2 for .NETCoreApp,Version=v1.0                                                                            
Compilation succeeded.                                                                                                          
    0 Warning(s)                                                                                                                
    0 Error(s)                                                                                                                  
Time elapsed 00:00:01.7208394                                                                                                   

Entity Framework .NET Core CLI Commands 1.0.0-preview2-21431
Usage: dotnet ef [options] [command]
Options:
  -h|--help                      Show help information
  -v|--verbose                   Enable verbose output
  --version                      Show version information
(... etc)

At first, I was getting No executable found matching command "dotnet-ef" until I realized that you have to execute the commands from inside the project folder (src\projectName in my case). If you try to do it from the solution root directory, it won't work.

7
7/12/2016 1:21:48 AM


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