15

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.

alex
  • 6,818
  • 9
  • 52
  • 103
even
  • 315
  • 4
  • 11
  • Could you please focus on the main subject of your question - evetually rephrase it and put it first? – rudolf_franek Mar 20 '17 at 09:14
  • You can use my VS extension, and avoid polluting your code with the scaffolding tooling: https://twitter.com/ErikEJ/status/834452863380250624 – ErikEJ Mar 20 '17 at 10:17
  • Presuming you followed the instructions on adding the reference in your csproj, you might try just opening a command prompt and changing to the directory with your .csproj and running the command there. I could not get it to work with the VS PS prompt but cmd.exe was good to go. – Erik Noren Mar 24 '17 at 06:09
  • Possible duplicate of [#37276882](https://stackoverflow.com/a/45765523/1233379): in short words, you need to manually edit your project configuration file and add a reference to the Tools / Tools.DotNet packages (as VS2015/VS2017 won't do that automatically). For further info, [read here](http://www.ryadel.com/en/no-executable-found-matching-command-dotnet-ef-error-in-visual-studio-2017-and-net-core-2-vs2017-entity-framework/). – Darkseal Aug 19 '17 at 05:57
  • Possible duplicate of [No executable found matching command "dotnet-ef"](https://stackoverflow.com/questions/37276882/no-executable-found-matching-command-dotnet-ef) – Michael Freidgeim Oct 20 '18 at 08:11

5 Answers5

15

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>
PROTOCOL
  • 371
  • 9
  • 17
5

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.

Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
3

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
etrupja
  • 2,710
  • 6
  • 22
  • 37
2

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

0

On NetCore 2.0 you just need to run Add-Migrations.

It will ask for a name and that's all. Just be sure you have a default connection string on appsettings.json