Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"No executable found matching command dotnet-ef" error with EF Core database-first

As you know, the newest version of Visual Studio 2017 abandons the 'project.json' and uses .csproj instead.

I'm using the RTM version and want to generate model from an exist database, following this guide. I got an error on the last step:

The Entity Framework Core commands for the Package Manager Console don't yet support csproj-based .NET Core projects. Use the .NET Command Line Tools (i.e. dotnet ef) instead. For more details, see https://go.microsoft.com/fwlink/?linkid=834381.

Following the error, I used the link it mentioned to switch to dotnet ef. Here is my package manager command:

PM> dotnet ef dbcontext scaffold "Server=.;Database=Jumpstart;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer

Then the error comes again:

dotnet : No executable found matching command "dotnet-ef"

I used the help command, I found that dotnet does not have a command called ef.

I just want to generate a model from an existing database.

like image 507
even Avatar asked Mar 20 '17 07:03

even


4 Answers

Follow this tutorial

https://learn.microsoft.com/en-us/aspnet/core/data/ef-mvc/migrations

I had the same problem. Just edited the ItemGroup section in .csproj like this

<ItemGroup>
   <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>
like image 146
PROTOCOL Avatar answered Oct 22 '22 23:10

PROTOCOL


Accepted answer is the most probable cause of the error message. However, besides adding the proper reference within .csproj file also make sure that the current directory from Package Manager Console points to ASP.NET Core project, otherwise any dotnet ef command will fail with the error mentioned in the OP title.

like image 21
Alexei - check Codidact Avatar answered Oct 23 '22 01:10

Alexei - check Codidact


My issue was solved by changing tools to:

"tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final",
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final"
  },

Then execute these 2 commands:

  1. dotnet restore - to restore packages
  2. dotnet ef migrations
like image 20
etrupja Avatar answered Oct 22 '22 23:10

etrupja


I solved the problem

in all answer mentioned adding Tools DotNet but not solved my problem because missed some command I mention below

The EF Core .NET Command Line Tools are installed by manually editing the *.csproj file.

Add Microsoft.EntityFrameworkCore.Tools.DotNet as a DotNetCliToolReference. See sample project below.

<ItemGroup>
   <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
</ItemGroup>

for core version 2 changed the version but after that should run 2 commands too

then importatn part in all answer missing (this command solved my problem in visuall studio 2017)

1 - Execute dotnet add package Microsoft.EntityFrameworkCore.Design

2 - Execute dotnet restore. If restore does not succeed, the tools may not have installed correctly.

more information https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet

like image 20
ebadola sobhanverdy Avatar answered Oct 23 '22 00:10

ebadola sobhanverdy