术语 'Scaffold-DbContext' 未被识别为 cmdlet 的名称

The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet

我有两个项目的解决方案,一个是主项目,第二个是将使用 EF Core 10.0 RC2 的项目。

在第二个项目中,我使用这三个命令来安装 EF Core,运行 这个 nuget 命令来安装它:

Install-Package Microsoft.EntityFrameworkCore.SqlServer –Pre
Install-Package Microsoft.EntityFrameworkCore.Tools –Pre
Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design –Pre

稍后我可以使用以下命令从数据库创建我的模型:

Scaffold-DbContext "'Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;'" Microsoft.EntityFrameworkCore.SqlServer

问题是,如果我退出 VS2015 并再次打开,如果我尝试 运行 相同的命令再次生成模型,我会收到此错误:

The term 'Scaffold-DbContext' is not recognized as the name of a cmdlet.

我不知道是什么问题,我已经尝试安装entityFrameworks.Commands但是问题没有解决。

你试过命令了吗:

dotnet restore --infer-runtimes

更多信息,您可以访问:https://github.com/aspnet/EntityFramework/issues/5549,它对某人有效。

不要忘记 运行 visual studio 作为管理员,否则你会得到那个错误