简体   繁体   English

无法在Visual Studio 2015 Web API项目中启用EF6迁移

[英]Unable to Enable EF6 Migrations in Visual Studio 2015 Web API project

In my VS2015 ASP.NET 5 Web API project I installed EF6.1.3 but the enable-migrations command in Package Manage console gives me following error: The term 'enable-migrations' is not recognized as the name of a cmdlet, function, script file, or operable program. 在我的VS2015 ASP.NET 5 Web API项目中,我安装了EF6.1.3,但Package Manage控制台中的enable-migrations命令给出了以下错误: The term 'enable-migrations' is not recognized as the name of a cmdlet, function, script file, or operable program. None of the suggestions here work for me - giving me still the same error 这里没有任何建议对我有用 - 给我仍然是同样的错误

UPDATE UPDATE

So far, I've tried the following commands and have closed/re-open the VS (even as administrator): 到目前为止,我已经尝试使用以下命令并关闭/重新打开VS(甚至以管理员身份):

Install-Package EntityFramework -IncludePrerelease

Update-Package –reinstall EntityFramework

Install-Package EntityFramework.Commands -Pre

Have you tried the following: 您是否尝试过以下方法:

Install-Package EntityFramework -IncludePrerelease Install-Package EntityFramework -IncludePrerelease

I had the same issue recently. 我最近遇到了同样的问题。

EntityFramework.Commands is designed for EF7 and is not compatible with EF6. EntityFramework.Commands专为EF7设计,与EF6不兼容。 It's no wonder 'enable-migrations' is missing because this is not a command in EF7 . 难怪'enable-migrations'缺失,因为这不是EF7中的命令

You can also try manually adding the EF module. 您也可以尝试手动添加EF模块。 All nuget does to import the commands is execute a small powershell file. nuget导入命令的全部工作是执行一个小的powershell文件。 You can do this yourself by manually finding and importing EntityFramework.psd1. 您可以自己手动找到并导入EntityFramework.psd1来完成此操作。 See https://entityframework.codeplex.com/SourceControl/latest#src/NuGet/EntityFramework/tools/init.ps1 请参阅https://entityframework.codeplex.com/SourceControl/latest#src/NuGet/EntityFramework/tools/init.ps1

Import-Module C:\MySolution\packages\EntityFramework.6.1.3\tools\EntityFramework.psd1

In theory NuGet should do this automagically anytime it opens, but with ASP.NET 5 tooling, the project model has changed and their may be nuget bugs in VS. 理论上,NuGet应该在它打开的任何时候自动执行此操作,但是使用ASP.NET 5工具,项目模型已经改变,它们可能是VS中的nuget错误。 Have you upgraded to the latest nuget tooling (v3.3.0)? 您是否已升级到最新的nuget工具(v3.3.0)? https://dist.nuget.org/index.html https://dist.nuget.org/index.html

I used the solution from this answer 我使用了这个答案的解决方案

You need to uninstall and then install the EntityFramework again. 您需要再次卸载然后再安装EntityFramework。 Just in case the uninstall failed because the EntityFramework used by other package as dependency, use command below to force the uninstall process. 万一由于其他程序包将EntityFramework用作依赖项而导致卸载失败,请使用以下命令强制执行卸载过程。

Uninstall-Package -f EntityFramework 卸载软件包-f EntityFramework

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM