简体   繁体   English

Scaffold-DbContext 在 .net 核心中抛出错误“找不到程序集”

[英]Scaffold-DbContext throws error “Could not find assembly” in .net core

I am using .net core and entity framework core 1.1.0.我正在使用 .net 核心和实体框架核心 1.1.0。 while trying the following command in Package Manager Console包管理器控制台中尝试以下命令时

Scaffold-DbContext "Server=MyServer\\MyInstance;Database=MyDB;user=MyUsername;password=MyDbPassword;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models -t Table1,Table2

I am getting this error我收到此错误

Could not find assembly 'D:\\Work\\Projects\\src\\MyProject\\src\\MyProject.Api.\\bin\\Debug\\net461\\win7-x64\\MyProject.Data.exe'.找不到程序集“D:\\Work\\Projects\\src\\MyProject\\src\\MyProject.Api.\\bin\\Debug\\net461\\win7-x64\\MyProject.Data.exe”。

MyProject.Data is a net core library. MyProject.Data 是一个网络核心库。 MyProject.Api is a .net full framework core api, which references the MyProject.Data. MyProject.Api 是一个 .net 完整框架核心 api,它引用了 MyProject.Data。

project.json file of MyProject.Data MyProject.Data 的 project.json 文件

{
  "version": "1.0.0-*",

  "dependencies": {
    "Microsoft.EntityFrameworkCore.Design": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": "1.1.0",
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final"
  },

  "frameworks": {
    "net461": {}
  }
}

Any advice for me?对我有什么建议吗?

Not sure if this is a bug, but scaffold-dbcontext command looks for the assembly in Startup Project .不确定这是否是一个错误,但scaffold-dbcontext命令在Startup Project 中查找程序集。

There are two workarounds for this issue此问题有两种解决方法

  1. Right click on the project you intend to run this command on (in your case, it is MyProject.Data) and select Set as startup project .右键单击要在其上运行此命令的项目(在您的情况下,它是 MyProject.Data)并选择Set as startup project
  2. You can pass a parameter to scaffold-DBContext command to set a particular project as startup project while running the command.您可以将参数传递给scaffold-DBContext命令,以在运行命令时将特定项目设置为启动项目。 This is what you need to add at the end of command...这是您需要在命令末尾添加的内容...

-StartupProject MyProject.Data

It seems that this issue also occurs if the target platform is x86.如果目标平台是 x86,似乎也会出现此问题。

Switching to AnyCPU solves the problem.切换到 AnyCPU 解决了这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Scaffold-DbContext时的ASP.NET Core Error - ASP.NET Core Error while using Scaffold-DbContext 在ASP.NET Core中支撑现有数据库(Scaffold-DbContext) - Scaffolding existing databases in ASP.NET Core (Scaffold-DbContext) Scaffold-DbContext SQL 视图? ASP 网络核心 3.1 - Scaffold-DbContext SQL Views ? ASP NET CORE 3.1 Scaffold-DbContext 失败。 System.TypeLoadException:无法在 .NET Core 上加载类型“Microsoft.EntityFrameworkCore.Internal.ProductInfo” - Scaffold-DbContext Fails. System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Internal.ProductInfo' on .NET Core EF Core 脚手架-dbcontext 自定义命名空间 - EF Core scaffold-dbcontext custom namespace 运行 Scaffold-DbContext 时出现超时错误 - Timeout error on running Scaffold-DbContext 无法将“System.DBNull”类型的对象转换为 Scaffold-DbContext .Net Core 中的“System.String”类型 - Unable to cast object of type 'System.DBNull' to type 'System.String' in Scaffold-DbContext .Net Core 在 Entity Framework Core 中调用 Scaffold-DbContext 时出现“异常调用 'GetFullPath'...”错误 - “Exception calling 'GetFullPath'…” error when calling Scaffold-DbContext in Entity Framework Core 仅在 EF Core 中的 Scaffold-DbContext 存储过程 - Scaffold-DbContext Stored Procedures only in EF Core 尝试 Scaffold-DbContext 的问题 - Issue trying to Scaffold-DbContext
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM