.NET Core Errors - Part One - Solution For “No Executable Found Matching Command “dotnet-ef”

ASP.NET-Core-Logo-blue

.NET Core was introduced in last few months and people have started adopting it.

In this series of posts, I will put some frequent issues during .NET Core development and some important topics for the Core.

In this post, we will see how to resolve the error,  No executable found matching command “dotnet-ef”.

This error comes when we want to migrate the database with the models and when we use below command.

dotnet ef migrations add FirstMigration

Reason

Because dotnet-ef tool might not have been added along with your template.

This error comes if you have not added Microsoft.EntityFrameworkCore.Tools in your Tools section of project.json file or if you have not added DotNetCliToolReference into the ItemGroup section, I will explain more in the below solution.

Solution

Below are some steps which you can try to resolve the error.

For .NET Core 2.0

  1. Add Microsoft.EntityFrameworkCore.SqlServer in your project. If it is not added yet, you can add them either using Nuget package by running below command,

    dotnet add package Microsoft.EntityFrameworkCore.SqlServer

  2. Add DotNetCliToolReference into the ItemGroup as below in your csproj file( for 99% cases, this should work)
    1. <ItemGroup>  
    2.     <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />  
    3.     <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />   
    4. </ ItemGroup>  
  3. If it does not work still, then add Microsoft.EntityFrameworkCore.Design Nuget package,

    dotnet add package Microsoft.EntityFrameworkCore.Design

For .NET Core 1.0

  1. Add Microsoft.EntityFrameworkCore.Tools and Microsoft.EntityFrameworkCore.Tools.DotNet in your project.json file, you can add them either using Nuget package or manually as below,
    1. "tools": {  
    2.     "Microsoft.EntityFrameworkCore.Tools""1.0.0"  
    3.     "Microsoft.EntityFrameworkCore.Tools.DotNet""1.0.0"  
    4. }  
  2. Add DotNetCliToolReference into the ItemGroup as below in your csproj file( for 99% cases, this should work),
    1. <ItemGroup>  
    2.     <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet">  
    3.         <Version>1.0.0-*</Version>  
    4.     </DotNetCliToolReference>  
    5. </ ItemGroup>  

Important Notes

  • Make sure that you are running the command from the folder that contains the project where the Tools package is referenced.

The error should be resolved now.