4

I started a project on a Mac using VS Code and ASP.NET Core MVC, here is my csproj:

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.0" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.0" />

    <PackageReference Include="System.Data.SqlClient" Version="4.3.0" />

    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" PrivateAssets="All" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" />
  </ItemGroup>

I always get "No executable found matching command "dotnet-ef""

I tried it on Windows 10 and I get the same result.

What am I missing?

  • 1. Please don't force tags into the title 2. Don't use ASP.NET Core and .NET Core interchangeably. They stand for completely different things – Tseng Mar 18 '17 at 02:33
  • Possible duplicate of [#37276882](https://stackoverflow.com/a/45765523/1233379): in short words, you need to manually edit your project configuration file and add a reference to the Tools / Tools.DotNet packages (as VS2015/VS2017 won't do that automatically). For further info, [read here](http://www.ryadel.com/en/no-executable-found-matching-command-dotnet-ef-error-in-visual-studio-2017-and-net-core-2-vs2017-entity-framework/). – Darkseal Aug 19 '17 at 05:58
  • Also make sure you're current path is the root folder of the project. If you create a folder for a project this may be a level deeper than you expected. – Peter Dec 17 '17 at 09:10

2 Answers2

11

Added this to make it work:

 <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version = "1.0.0"/>
  </ItemGroup>
5
  1. From inside the folder containing the csproj file, Add the following to the csproj file:

    <PropertyGroup>
        <TargetFramework>netcoreapp2.0</TargetFramework>
        <RuntimeFrameworkVersion>2.0.5</RuntimeFrameworkVersion>
    </PropertyGroup>
    
    <ItemGroup>
        <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
    </ItemGroup>
    
  2. Now include the needed dependencies by executing the following commands:

    dotnet add package Microsoft.EntityFrameworkCore dotnet add package Microsoft.EntityFrameworkCore.Design dotnet add package Microsoft.EntityFrameworkCore.SqlServer dotnet add package Microsoft.EntityFrameworkCore.Tools.DotNet

  3. Restore the project so that all dependencies are checked upon dotnet restore

  4. In order to make sure it all went ok, run the following command dotnet ef A screen with the basic dotnet ef command usage should appear

  5. Check if the project is still building: dotnet build

  6. Generate the scaffold from your database with the following command:

dotnet ef dbcontext scaffold "Server=<your_server_address[,port_number]>;Initial Catalog=<your_db>;User Id=<your_user>;Password=<your_password>" Microsoft.EntityFrameworkCore.SqlServer -f -c YourDbContext -o Db --json

The command above can be described as the one responsible for reading out your database and generating your scaffold poco entity classes and the dbcontext file. It requires a basic working connection string, the parameter f forces the overwrite, the c gives the context a name, the o determines the output folder and the namespace for the created classes and the json parameter outputs the command result in json instead of a zero stout.

it is nice to keep this command at hand, it will be used anytime changes from the database must be reflected upon the ORM

MarcoSantana
  • 667
  • 10
  • 10