.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
- 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
- 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>
- If it does not work still, then add Microsoft.EntityFrameworkCore.Design Nuget package,
dotnet add package Microsoft.EntityFrameworkCore.Design
For .NET Core 1.0
- 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"
- }
- 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.