Could not load assembly Microsoft.EntityFrameworkCore.Design when running Add-Migration

旧巷老猫 提交于 2019-12-05 17:25:33

It worked after adding Microsoft.EntityFrameworkCore.Tools.DotNet and changing the versions of dotnet tools to 1.0.0-msbuild2-final, now my .csproj is:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.sqlserver.Design" Version="1.1.1" />
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.0.0-msbuild2-final" />
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0-msbuild2-final" />
  </ItemGroup>

</Project>

for me, it worked fine after setting the start up project to the class library also you can do it without setting the start up project by using the command

Add-Migration -project [ProjectName] initDB

also here is my .csproj for reference

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </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" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore" Version="1.1.2" />  
    <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
</ItemGroup>


</Project>

I followed instructions from Bart Lannoeye:

UWP apps can’t run in the AnyCPU configuration I chanbged my project to run in x86 and migrations started to work.

http://www.bartlannoeye.com/blog/ef-core-migrations-throws-exception-calling-createinstanceandunwrap

My issue was a specific version of Visual Studio (15.4.5) failing to read the IDE settings. From this workaround from Ben Day I explicitly set the setup project and Migrations project on the command line.

These two commands were formatted in this manner to make it work.

PM> cd [migrations directory]
PM> Add-Migration -Name [version label] -Context [your context] -s [startup project]
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!