我正在使用.NET Core Console应用程序,我在安装所需的EF依赖项之后尝试构建数据库。这是project.json:
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.EntityFrameworkCore": "1.0.1",
"Microsoft.EntityFrameworkCore.Design": "1.0.1",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.1",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
}
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": {
"version": "1.0.0-preview2-final"
}
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
在程序包管理器控制台中运行此命令时:
PM> Scaffold-DbContext "Server=PC;Database=DB;User Id=sa;Password=pass;" Microsoft.EntityFrameworkCore.SqlServer -OutputDir EntityModels
它给了我以下内容:
未处理的异常:System.MissingMethodException:在程序集“Microsoft.EntityFrameworkCore.Design,Version = 1.0.1.0,Culture = neutral,PublicKeyToken = adb9793829ddae60'中找不到入口点。
然后,我安装了最新版本的Microsoft.EntityFrameworkCore.Tool(版本3),现在执行scaffold命令时,它提供了以下内容:
c:.... \ project.json
中的无效JSON文件
答案 0 :(得分:0)
不确定这是否是您唯一的问题,但我有"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview3-final"
。确保所有的核心都是最新的。另外,请确保您使用的是Visual Studio 2015 Update 3,最新工具和最新核心等。此外,至少还有PowerShell 3(我使用4)。
答案 1 :(得分:0)
使用1.0.1时遇到了同样的问题。这不是理想的,但在将来的版本中解决此问题之前,我在运行1.0.0-preview2-final
时使用版本Microsoft.EntityFrameworkCore.Design
dotnet ef dbcontext scaffold
,然后在脚手架时恢复为1.0.1过程完成。
确保在每次project.json更改后执行包恢复。
这是我的project.json:
{
"dependencies": {
"NETStandard.Library": "1.6.0",
"Microsoft.EntityFrameworkCore": "1.0.1",
// use this version to build/run
"Microsoft.EntityFrameworkCore.Design": "1.0.1",
// use this version when running `dotnet ef dbcontext scaffold`
//"Microsoft.EntityFrameworkCore.Design": {
// "type": "build",
// "version": "1.0.0-preview2-final"
//},
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.1",
"Microsoft.EntityFrameworkCore.SqlServer.Design": "1.0.1",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"System.Linq.Dynamic.Core": "1.0.6.5",
"AutoMapper.Extensions.Microsoft.DependencyInjection": "1.1.2"
},
"tools": {
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
},
"buildOptions": {
"emitEntryPoint": true
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1-*"
}
}
}
}
}