我正在尝试使用PM Console使用EntityFramework Core运行命令Add-Migration(代码优先方法)。我无法克服此错误: 无法执行此命令,因为未安装Microsoft.EntityFrameworkCore.Design。安装与Microsoft.EntityFrameworkCore的已安装版本匹配的那个软件包的版本,然后重试。 这是我的project.json文件:
{ "dependencies": { "Microsoft.NETCore.App": "1.1.0", "Microsoft.AspNetCore.Mvc": "1.0.1", "Microsoft.AspNetCore.Routing": "1.1.0", "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0", "Microsoft.AspNetCore.Server.Kestrel": "1.0.1", "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0", "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0", "Microsoft.Extensions.Configuration.Json": "1.0.0", "Microsoft.Extensions.Logging": "1.1.0", "Microsoft.Extensions.Logging.Console": "1.0.0", "Microsoft.Extensions.Logging.Debug": "1.0.0", "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0", "Microsoft.EntityFrameworkCore": "1.1.0", "Microsoft.EntityFrameworkCore.SqlServer": "1.1.0", "Microsoft.EntityFrameworkCore.Design": "1.1.0" }, "tools": { "Microsoft.EntityFrameworkCore.Tools.DotNet": "1.1.0-preview4-final", "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final" }, "frameworks": { "netcoreapp1.0": { "imports": [ "dotnet5.6", "portable-net45+win8" ] } }, "runtimes": { "win10-x64": {} }, "buildOptions": { "emitEntryPoint": true, "preserveCompilationContext": true }, "runtimeOptions": { "configProperties": { "System.GC.Server": true } }, "publishOptions": { "include": [ "wwwroot", "**/*.cshtml", "appsettings.json", "web.config" ] }, "scripts": { "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ] } }
如您所见,我的依赖项和工具是1.1.0版。这些是我的参考:
我尝试过的事情:
关闭/重新打开Visual Studio
点网还原
我的启动文件在ConfigServices中注册了我的连接字符串
我已经安装了所有我应该知道的东西。我也查看了其他有关StackOverflow上此问题的帖子,但均无济于事。
任何人都可以克服这个吗?感谢您的帮助。
首先,修复netcoreapp1.0
和之间的不一致"Microsoft.NETCore.App": "1.1.0"
其次,您需要Microsoft.EntityFrameworkCore.Tools
运行PM-Console命令。
现有Microsoft.EntityFrameworkCore.Tools.DotNet
用于dotnet CLI命令。您可以创建dotnet ef migrations add
从命令行运行的迁移。
有关使用PM和/或CLI的详细信息在这里