运行 Dotnet EF 迁移添加 ... 在 运行 时生成 FileNotFoundException

Running Dotnet EF migrations add ... generates FileNotFoundException when run

产生的错误如下。

System.IO.FileNotFoundException: Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The system cannot find the file specified.
File name: 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes'
   at Microsoft.DotNet.ProjectModel.ProjectReader.ReadProject(Stream stream, String projectName, String projectPath, ProjectReaderSettings settings)
   at Microsoft.DotNet.ProjectModel.ProjectReader.GetProject(String projectPath, ProjectReaderSettings settings)
   at Microsoft.EntityFrameworkCore.Tools.DispatchCommand.<>c__DisplayClass2_0.<Create>b__0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.EntityFrameworkCore.Tools.Program.Main(String[] args)
Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The system cannot find the file specified.

任何 DOTNET EF 命令(甚至 --help)都会出现此错误

我们有多台机器可以正常工作,但其中有 2 台机器出现上述错误,这很令人沮丧?

我什至尝试只安装来自 Github 的 ProjectModel 组件,但没有成功

感谢任何有关如何解决此问题的帮助

我遇到了这个问题(以及其他类似错误 运行 其他 dotnet 命令。对我来说,这是由于安装了较旧的 RC1 和 SDK。我从 add/remove 程序中删除了所有内容,以及删除 c:\program files 中的 dotnetDNX 目录。然后我重新安装并开始工作。

我尝试了卸载和删除所有 DNX 和 DOTNET 目录的建议,但无济于事。

然后我又做了一些搜索并找到了答案。我不得不将我的工具 - entityframework 配置更改为以下

"Microsoft.EntityFrameworkCore.Tools": {
  "version": "1.0.0-preview1-final",
  "imports": "portable-net451+win8"

},

然后我必须按照这篇文章 link 清除 Entity Framework 的缓存 https://github.com/aspnet/EntityFramework/issues/5458#issuecomment-221912806

然后我需要从项目中删除 Microsoft.EntityFrameworkCore.SqlServer 的引用,然后让 VS 通过重新加载

来修复引用本身

在此之后,构建解决了问题,我可以再次 运行 dotnet ef 命令