Solution for the error “No executable found matching command “dotnet-ef” : .Net Core Errors Part I

ASP.NET-Core-Logo-blue

.Net Core was introduced in last few months and people has started adopting it.

In this series of post, 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 have not 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 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):

<ItemGroup>
  <DotNetCliToolReference 
      Include="Microsoft.EntityFrameworkCore.Tools" 
      Version="2.0.0" />
  <DotNetCliToolReference 
      Include="Microsoft.EntityFrameworkCore.Tools.DotNet" 
      Version="2.0.0" /> 
</ 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:
"tools": {
   "Microsoft.EntityFrameworkCore.Tools": "1.0.0"
   "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.0.0"
 }

2. Add DotNetCliToolReference into the ItemGroup as below in your csproj file( for 99% cases, this should work):

<ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet">
      <Version>1.0.0-*</Version>
</DotNetCliToolReference>
    </ 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.

 

Advertisement

3 thoughts on “Solution for the error “No executable found matching command “dotnet-ef” : .Net Core Errors Part I

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s