The "No executable found matching command dotnet-ef" error

At the time of writing, there's a nasty issue affecting most .NET Core-based Visual Studio projects that can prevent the dotnet ef command from working properly. More specifically, you can be prompted by the following error message when trying to execute that command:

No executable found matching command "dotnet-ef"

If you experience this issue, try to check the following:

  • Double-check that you properly added the Microsoft.EntityFrameworkCore.Tools and the Microsoft.EntityFrameworkCore.Tools.DotNet package libraries (as explained earlier), as they are required for the command to work
  • Ensure that you are issuing the dotnet ef command in the project's root folder--the same one that also contains the <ProjectName>.csproj file; it won't work anywhere else

If both of these checks hit their marks, try this workaround--right-click on the project's root folder, select Edit <ProjectName>.csproj to open that file to edit in Visual Studio, and look for the following element:

<ItemGroup>
<DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools"
Version="2.0.1" />

<DotNetCliToolReference
Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />

</ItemGroup>
Alternatively, you can also edit the <ProjectName>.csproj file with a text editor such as Notepad++; just ensure that you reload your project when you're done.

The <ItemGroup> element is just a container here; you need to look for the highlighted lines. Needless to say, the Version value will change when using a different or more recent EF Core release. Be aware that these elements can have a slightly different syntax.

However, they definitely need to be there; if you can't find them, you will know why the dotnet ef command is not working. Fix that unwanted behavior by manually adding them to your project configuration file. They must we wrapped within an <ItemGroup> block, so you can either put them together in a group with other <DotNetCliToolReference> elements (if there is at least one), or add a whole net <ItemGroup> block.

As soon as you update your project configuration file, restart Visual Studio (or reload the project), and then try to execute the dotnet ef command again from the project's root folder. In the unlikely case that you end up with some NuGet package conflicts, you can try issuing the dotnet update command from the project's root folder to fix them; right after that, reload your project and try to execute the dotnet ef command again.

A lot more can be said regarding this issue, but doing that will bring us too far from the scope of this book. If you want to know more, you can take a look at the article I wrote about it while working on this book at https://goo.gl/Ki6mdb.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.14.251.128