';微软EntityFrameworkCore.工具';未安装在Scaffold DbContext上的项目
本文关键字:DbContext 项目 Scaffold 微软 EntityFrameworkCore 工具 安装 | 更新日期: 2023-09-27 17:58:49
我正在学习这里列出的教程:
https://docs.efproject.net/en/latest/platforms/aspnetcore/existing-db.html
但是,我不希望在WebApplication项目中包含DB上下文,而是希望DB上下文、实体等位于另一个项目中。NET核心类库。
通过更新libraries project.json文件以包含"netcoreapp1.0"框架,我解决了一些早期的兼容性问题。
project.json
之前:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
之后:
{
"version": "1.0.0-*",
"frameworks": {
"netcoreapp1.0": {
"imports": [ "portable-net451+win8" ],
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-*"
},
"Microsoft.EntityFrameworkCore": "1.0.0-*",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-*"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-*"
}
},
"netstandard1.6": {
"imports": "dnxcore50",
"dependencies": {
"NETStandard.Library": "1.6.0"
}
}
}
}
教程接着说,为了"逆向工程您的模型",必须在包管理器控制台中运行以下命令:
Scaffold-DbContext "Server=(localdb)'mssqllocaldb;Database=Blogging;Trusted_Connection=True;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
我收到以下错误消息:
Cannot execute this command because 'Microsoft.EntityFrameworkCore.Tools' is not installed in project 'src'DB'. Add 'Microsoft.EntityFrameworkCore.Tools' to the 'tools' section in project.json. See http://go.microsoft.com/fwlink/?LinkId=798221 for more details.
其中DB是类库的名称。
你可以清楚地看到微软。EntityFrameworkCore。工具部分中的工具。所以我不知道该怎么办。
project.json模式中定义的"framework"部分中没有工具部分。
这个应该能正常工作
{
"version": "1.0.0-*",
"dependencies": {
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.0",
"Microsoft.EntityFrameworkCore": "1.0.0-*",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-*"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-*"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [ "portable-net451+win8" ],
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0-*"
}
}
},
"netstandard1.6": {
"imports": "dnxcore50",
"dependencies": {
"NETStandard.Library": "1.6.0"
}
}
}
}