Base solution for your next web application
Open Closed

No executable found matching command "dotnet-ef" #3281


User avatar
0
bsolutions created

Hi everyone!

I'm trying to use the new .NET Core 1.1 template of ASP.NET Boilerplate but I have problems with migrations.

I compiled the complete solution, set the Web.Mvc project as startup project and then I opened a command prompt with administration rights. I went to the EntityFrameworkCore directory and executed the following command:

"dotnet ef database update"

I got this result:

No executable found matching command "dotnet-ef"

When I changed to the Web.Mvc directory and tried to execute the command here, the result was:

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:10.05
No DbContext was found in assembly 'BSolutions.BreconsShop.Web.Mvc'. Ensure that you're using the correct assembly and that the type is neither abstract nor generic.

So the "dotnet ef" possibly exists, but don't run in the EntityFrameworkCore directory. Do anyone have a solution for that problem?


5 Answer(s)
  • User Avatar
    0
    bsolutions created

    I found a Solution!

    With the new .NET Core 1.1 template you can use the Package Manager Console within Visual Studio to add migrations or update the database:

    1. Set the Web.Mvc project as start-up project
    2. Open Package Manager Console and set the EntityFrameworkCore project as default project. 3a. Use Add-Migration <NAME> to add a new migration. 3b. Use Update-Database to update the database with the latest migration.

    I hope the boilerplate crew updates the documentation as fast as can be ;)

  • User Avatar
    0
    ismcagdas created
    Support Team

    Thanks @bsolutions,

    We didn't notice this, we will upgrade our documents.

  • User Avatar
    0
    fengol created

    While you might be able to use the older Entity Framework tools the real reason for the problem is the .EntityFrameworkCore project file is missing a reference to the CLI tools.

    Edit the .EntityFrameworkCore.csproj file and add this reference package

    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" />
    

    I also recommend updating the versions of the other packages

    <ItemGroup>
        <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" />
      </ItemGroup>
    

    Then you must add the .NET CLI tool reference by adding another ItemGroup

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

    Now run dotnet restore in either the solution or the project folder and it will download the EFCore tools and enable them for the .EntityFrameworkCore project.

    You should then be able to run dotnet ef and see the EFCore driver has been loaded.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @Fengol,

    Thank you for sharing this. We added this for AspNet Zero but forgot to add it for free templates. We will fix it for the next release.

    Thanks again.

  • User Avatar
    0
    bsolutions created

    Thanks @Fengol! That is the best solution!

    For the sake of completeness here the new *.csproj file:

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>netcoreapp1.1</TargetFramework>
        <PackageTargetFallback>$(PackageTargetFallback);dotnet5.6;portable-net45+win8</PackageTargetFallback>
        <RootNamespace>CompanyName.ProductName</RootNamespace>
        <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
      </PropertyGroup>
      <ItemGroup>
        <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" />
      </ItemGroup>
      <ItemGroup>
        <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" />
      </ItemGroup>
    </Project>