在 MVC 中启用迁移会抛出文件未找到错误

Enable Migrations in MVC throws File not Found Error

我是使用 MVC 的新手,在 Visual Studio 2013 年学习有关迁移的教程时,我似乎在包管理器控制台中破坏了与 EntityFramework 的关联。

我相信这是在我将 EntityFramework 更新到版本 6.1.3 时开始的,但这似乎与 MVC 控制器脚手架不兼容。所以我把它回滚到版本 5.0.0.

当我现在输入命令enable-migrations

我收到以下错误:

Exception calling "CreateInstanceFrom" with "8" argument(s): "Could not load file or assembly 'EntityFramework, Version=5.0.0.0 , Culture=neutral, PublicKeyToken=b77a5c561934e089' or one of its dependencies. The system cannot find the file specified." At D:\ss\CAP\CAP_MVC_Dev_2\CAP_MVC\packages\EntityFramework.5.0.0\tools\EntityFramework.psm1:431 char:31 + $domain.CreateInstanceFrom <<<< ( + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodTargetInvocation

文件 EntityFramework.psm1 存在于上述位置,但错误似乎出在该文件中? $domain.CreateInstanceFrom 怎么不见了,从哪里来的?卸载并重新安装 EntityFramework 包没有任何区别。

我试过从头开始创建新项目,但这个错误仍然存​​在。 Visual Studio 2013 的 uninstall/reinstall 也没有解决问题,也没有破坏连接的数据库并从一个空的数据库重新开始。

原来解决方案与这个类似

Entity Framework code first migrations throwing error

当我第一次尝试这个解决方案时,有报告说 gacutil 没有被识别。由于我工作的环境,添加 gacutil 被普遍认可并不简单(我相信),所以我在文件系统中找到 gacutil.exe,将其复制到引用的 lib\net45 文件夹中链接 post,然后 运行 命令

gacutil /i EntityFramework.dll

这已解决问题,我不再收到 'File not Found error'

我没有使用 GAC 安装,而是采用了以下解决方案 (VS2013 SP5 + EF 5):

已复制 (解决方案目录)\packages\EntityFramework.5.0.0(整个目录) 至

C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\EFTools\NuGet Packages\

NuGet Packages 目录不存在,需要手动创建。