我想按照本教程使用 EF Core 创建控制台应用程序:http://ef.readthedocs.io/en/latest/platforms/full-dotnet/new-db.html .
我的问题是,我无法执行语句
Add-Migration
如教程中所述。它向我展示:
PM> Add-Migration MyFirstMigration
Cannot execute this command because 'Microsoft.EntityFrameworkCore.Tools' is not installed in project 'src\AppEf'. Add 'Microsoft.EntityFrameworkCore.Tools' to the 'tools' section in project.json. See http://go.microsoft.com/fwlink/?LinkId=798221 for more details.
所有添加的程序集:
怎么了?
更新
dotnet restore
语句有效,而 dotnet-ef --help
根本不起作用。
可以看到,语句是在项目文件夹中执行的。
最佳答案
正如一些人在评论中提到的,Microsoft.EntityFrameworkCore.Tools
需要添加到 project.json 的 tools
部分。
我已经使用最新(2016 年 7 月)版本的 EF Core 和工具包测试了这个 project.json,它有效:
{
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.Design": {
"version": "1.0.0-preview2-final",
"type": "build"
},
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"frameworks": {
"netcoreapp1.0": {}
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
},
"version": "1.0.0-*"
}
要使用它,请从项目文件夹的内部执行这些命令:
λ dotnet restore
log : Restore completed in 2810ms.
λ dotnet ef --help
Compiling EfCoreTester2 for .NETCoreApp,Version=v1.0
Compilation succeeded.
0 Warning(s)
0 Error(s)
Time elapsed 00:00:01.7208394
Entity Framework .NET Core CLI Commands 1.0.0-preview2-21431
Usage: dotnet ef [options] [command]
Options:
-h|--help Show help information
-v|--verbose Enable verbose output
--version Show version information
(... etc)
起初,我得到的是 No executable found matching command "dotnet-ef"
直到我意识到你必须从项目文件夹 (src\projectName
在我的例子中)。如果您尝试从解决方案根目录执行此操作,它将不起作用。
关于c# - 添加迁移失败,因为未安装 EntityFrameworkCore.Tools,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38306791/