5

When I want to add a migration to my project I got the following error:

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

For resolving this I add the following package but I still get the same error.

Microsoft.EntityFrameworkCore.Design(2.0.0)
Microsoft.EntityFrameworkCore.Tools.DotNet(2.0.0)

I found some solution but these are based on .net-core-1 and in .net-core-2 we don't have project.json file.

update:

Here is my .csproj file:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
</ItemGroup>
<ItemGroup>
<Reference Include="Microsoft.Extensions.Configuration">
      <HintPath>C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.extensions.configuration\2.0.0\lib\netstandard2.0\Microsoft.Extensions.Configuration.dll</HintPath>
   </Reference>
</ItemGroup>

</Project>
mohammad
  • 1,082
  • 2
  • 10
  • 22

3 Answers3

12

In order to get dotnet ef to work, you need to add a DotNetCliToolReference element to the .csproj, as follows:

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

This needs to live inside an ItemGroup, something like:

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

You'll also need to make sure you run dotnet ef from the same location as the .csproj file.

Kirk Larkin
  • 60,745
  • 11
  • 150
  • 162
  • 1
    I have two `.csproj` file in `obj` folder, `CoreSample.Model.csproj.nuget.g.props` and `CoreSample.Model.csproj.nuget.g.targets`. I add `..` in both of them but I still got same error. – mohammad Sep 05 '17 at 08:53
  • 1
    You can just right-click on the project and select `Edit XXX.csproj`, which will allow you to make the changes within Visual Studio. – Kirk Larkin Sep 05 '17 at 09:07
3

Answer

Link to thread

Above worked for me after many hrs trying many other thread answers. Simply cd'ing to folder containing csproj file in package console manager was all it took. dotnet ef commands all work fine then.

Bob Mack
  • 123
  • 1
  • 8
  • Thanks MS for the frustratingly UNHELPFUL error messages - unacceptable for something like wrong folder.....sheesh. – Jester Mar 27 '18 at 16:55
0

I know some of you will come to this question for the [No executable found matching command “dotnet-”] part of the title. In my case it was:

No executable found matching command “dotnet-My”

And.... it turns out my app name was "My App". Make sure your assembly name has no spaces in it. I changed it to "MyApp" and it loaded correctly.

Guillermo Prandi
  • 1,246
  • 1
  • 13
  • 24