EF Core:Scaffold DbContext一直都失败了

Arr*_*rrr 8 c# asp.net-mvc entity-framework

官方ASP.Net Core表示可以通过重启visual studio来修复以下错误:

 Scaffold-DbContext : The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
Run Code Online (Sandbox Code Playgroud)

但是命令仍然失败.

我按照ASP.Net核心在线文档中提供的示例在Package Manager控制台中运行它.

Scaffold-DbContext "Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
Run Code Online (Sandbox Code Playgroud)

Nic*_*eer 5

我遇到了同样的问题。对我来说是EntityFrameworkCore.Tools丢失了,并且没有通过NuGet正确安装。

在包管理器控制台(Tools > NuGet Package Manager > Package Manager Console)中运行以下命令:

Install-Package Microsoft.EntityFrameworkCore.SqlServer –Pre 
Install-Package Microsoft.EntityFrameworkCore.Tools –Pre 
Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design –Pre
Run Code Online (Sandbox Code Playgroud)

然后在project.json中添加了以下内容:

"tools": {
    "Microsoft.EntityFrameworkCore.Tools": "1.1.0-preview4-final",
}
Run Code Online (Sandbox Code Playgroud)

重要!确保此版本与 “ dependencies”包匹配(也在project.json中)。在此示例中,还应在依赖项中使用 “ 1.1.0-preview4-final”

如果问题仍然存在,请尝试还原您的ef运行时,该指南位于此处:https : //github.com/aspnet/EntityFramework/issues/5549