Database scaffolding stopped working in .Net Core 1.1

1.7k views Asked by At

We upgraded our .Net Core 1.0 projects to .Net Core 1.1 and realized that we can no longer scaffold databases in EF Core. Here is the project.json file:

 {
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "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",
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.1.0"
    }
  },
  "tools": {
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
    "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.1.0-preview4-final"
  },
  "frameworks": {
    "netcoreapp1.1": {
      "imports": "dnxcore50"
    }
  }
}

When the command below is run in PM console, the following error message is generated: Unrecognized option '--build-base-path'

Scaffold-DbContext "Server=(localdb)\ProjectsV13;Database=MyDatabase;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

Googling it was not conclusive. Any workarounds or ways to fix it?

1

There are 1 answers

0
user1920998 On BEST ANSWER

With .NET Core 1.1 you have to do it on the command line. See following link for the documentation:

https://learn.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet

I had additionally the problem, that my PATH wasn't correct. I had to add C:\Program Files\dotnet\bin because it was missing.

On the command line, go to your project directory and enter

dotnet ef dbcontext scaffold "Server=<Your Server>;Database=<Your Database>;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer --output-dir <Your path for the model classes> --force

and voila, after a second the sources are generated...

Hope this helps
Klaus