efcore icon indicating copy to clipboard operation
efcore copied to clipboard

Could not load file or assembly Microsoft.EntityFrameworkCore.Design

Open Cuiqs76 opened this issue 9 years ago • 9 comments

Run commond add-migration initialize throw errors in PM:` Exception message: Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Culture=neutral, PublicKeyToken=null'.

Stack trace: PM> add-migration initialize System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Culture=neutral, PublicKeyToken=null'. 系统找不到指定的文件。 File name: 'Microsoft.EntityFrameworkCore.Design, Culture=neutral, PublicKeyToken=null' at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) at System.Reflection.Assembly.Load(AssemblyName assemblyRef) at Microsoft.EntityFrameworkCore.Tools.ReflectionOperationExecutor..ctor(String assembly, String startupAssembly, String projectDir, String contentRootPath, String dataDirectory, String rootNamespace, String environment) at Microsoft.EntityFrameworkCore.Tools.Commands.ProjectCommandBase.CreateExecutor() at Microsoft.EntityFrameworkCore.Tools.Commands.MigrationsAddCommand.Execute() at Microsoft.DotNet.Cli.CommandLine.CommandLineApplication.Execute(String[] args) at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args) Could not load file or assembly 'Microsoft.EntityFrameworkCore.Design, Culture=neutral, PublicKeyToken=null'. 系统找不到指定的文件。

c# In data project: <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFramework>netcoreapp1.1</TargetFramework> </PropertyGroup> <ItemGroup> <PackageReference Include="Autofac" Version="4.4.0" /> <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.1" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.0" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\Yiko.Common\Yiko.Common.EfCore\Yiko.Common.EfCore.csproj" /> <ProjectReference Include="..\Yiko.Ent.Setting.Domain\Yiko.Ent.Setting.Domain.csproj" /> </ItemGroup> <ItemGroup> <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="1.0.0" /> </ItemGroup> </Project>

in WebApi project: <Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp1.1</TargetFramework> </PropertyGroup> <PropertyGroup> <GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles> </PropertyGroup> <ItemGroup> <Folder Include="wwwroot\" /> </ItemGroup> <ItemGroup> <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" /> <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" /> <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" /> <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.Extensions.Logging.Debug" Version="1.1.1" /> <PackageReference Include="Autofac" Version="4.4.0" /> <PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.0.0" /> </ItemGroup> <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\Yiko.Common\Yiko.Common.AspNetCore\Yiko.Common.AspNetCore.csproj" /> <ProjectReference Include="..\Yiko.Ent.Setting.Application\Yiko.Ent.Setting.Application.csproj" /> <ProjectReference Include="..\Yiko.Ent.Setting.Data\Yiko.Ent.Setting.Data.csproj" /> </ItemGroup> </Project>

Further technical details

EF Core version: 1.1.1 Database Provider: Microsoft.EntityFrameworkCore.SqlServer Operating system: IDE: Microsoft Visual Studio Community 2017 version 15.1 (26315.0-Preview) Preview VisualStudio.15.Preview/15.1.0-Preview+26315.0 Microsoft .NET Frameworkv version : 4.6.01586

Remark: the vs 2017 Community is also have the same problem, so i update to preview, but the error still exist.

Cuiqs76 avatar Mar 24 '17 09:03 Cuiqs76

How many project are in your solutions? Try to set on the project you are doing migration with right-click and "Set as startup project" I had the same problem before

sonphnt avatar Mar 24 '17 13:03 sonphnt

@sonphnt thanks

DeyiXu avatar Mar 31 '17 02:03 DeyiXu

@sonphnt thanks

shenniubuxing3 avatar Apr 12 '17 08:04 shenniubuxing3

@sonphnt tks.

IgorMoreira avatar Apr 19 '17 23:04 IgorMoreira

@sonphnt Thank you so much :)

namdeom avatar May 25 '17 04:05 namdeom

Good call. Temporarily set the project that contains EF Core as the Start-Up Project. Thanks!!

robvet avatar Jul 04 '17 22:07 robvet

https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet this link is helpful.

ashish005 avatar Jul 24 '17 16:07 ashish005

Thanks

nafberger avatar Aug 08 '17 18:08 nafberger

To summarise the steps you may need to get round this:

  • Temporarily set the project that will contain your migration code files as your startup project in Visual Studio (this might be a 'Data' or 'DataBase' project in your solution, or something similar)
  • Also set the 'Default project' in the Package Manager Console to the same project.
  • Run the Add-Migration command in the Package Manager Console

chalcrow avatar Jul 06 '18 05:07 chalcrow