Scaffold-DbContext throws error "Could not find assembly" in .net core

.net .net-core c# entity-framework-core scaffolding

Question

I am using .net core and entity framework core 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'.

MyProject.Data is a net core library. MyProject.Api is a .net full framework core api, which references the MyProject.Data.

project.json file of MyProject.Data

{
  "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?

1
3
11/25/2016 11:32:36 AM

Popular Answer

Not sure if this is a bug, but scaffold-dbcontext command looks for the assembly in 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.
  2. You can add a switch to scaffold-DBContext command to set a particular project as startup project while running the command. This is what you need to add at the end of command...

    -StartupProject MyProject.Data

7
8/29/2018 12:04:29 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow