Monday, March 19, 2018

Entity Framework Core - No executable found matching command "dotnet-ef"

After adding the EntityFramework nuget package to my ASP.NET Core project and creating our DbContext(see below) I was ready to generate a first migration :

I opened the Package Manager Console in Visual Studio, browsed to the project folder(!),  and executed dotnet ef. I ended up with the following error message:

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

At line:1 char:1

+ dotnet ef

+ ~~~~~~~~~

    + CategoryInfo          : NotSpecified: (No executable f...and "dotnet-ef":String) [], RemoteExcep

tion

    + FullyQualifiedErrorId : NativeCommandError

To solve this install the following 2 extra packages:

  • Microsoft.EntityFrameworkCore.Tools: Contains the Entity Framework Core Package Manager Console Tools. Includes Scaffold-DbContext, Add-Migration, and Update-Database.
  • Microsoft.EntityFrameworkCore.Tools.DotNet: Contains the Entity Framework Core .NET Command-line Tools. Includes dotnet-ef.

Remark: When trying to install the Microsoft.EntityFrameworkCore.Tools.DotNet package, I got the following error message:

image

I solved it by adding the package directly to the csproj file:

After doing that run a dotnet restore first. If you now try to execute dotnet ef, it should work:

image

No comments: