15
votes

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.

5
Could you please focus on the main subject of your question - evetually rephrase it and put it first?rudolf_franek
You can use my VS extension, and avoid polluting your code with the scaffolding tooling: twitter.com/ErikEJ/status/834452863380250624ErikEJ
Presuming you followed the instructions on adding the <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" /> 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
Possible duplicate of #37276882: 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.Darkseal

5 Answers

15
votes

Follow this tutorial

https://docs.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>
5
votes

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.

3
votes

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
2
votes

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://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet

0
votes

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