This forum is not used anymore. Please ask new questions to Stack Overflow: https://stackoverflow.com/questions/tag ... ort=newest (use aspnetboilerplate tag).
By bsolutions
#18994 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:

Code: Select all"dotnet ef database update"

I got this result:

Code: Select allNo executable found matching command "dotnet-ef"

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

Code: Select allBuild 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?
By bsolutions
#19004 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
By Fengol
#19092 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

Code: Select all <PackageReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.1" />


I also recommend updating the versions of the other packages
Code: Select all  <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
Code: Select all  <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.
By bsolutions
#19393 Thanks @Fengol! That is the best solution!

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

Code: Select all<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>