c# - Entity Framework Core 1.1.2 迁移异常

标签 c# .net-core entity-framework-core entity-framework-migrations

我遇到了奇怪的异常。

我已经看到以下线程讨论将 Microsoft.EntityFrameworkCore.Tools 降级到 1.1.1,我已经这样做了,但仍然出现这些异常。

System.ArgumentNullException: Value cannot be null.
Parameter name: contentRootPath
   at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)
   at Microsoft.EntityFrameworkCore.Design.Internal.MigrationsOperations..ctor(IOperationReporter reporter, Assembly assembly, Assembly startupAssembly, String environment, String projectDir, String contentRootPath, String rootNamespace)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.<>c__DisplayClass4_0.<.ctor>b__4()
   at Microsoft.EntityFrameworkCore.Internal.LazyRef`1.get_Value()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.AddMigrationImpl(String name, String outputDir, String contextType)
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.<>c__DisplayClass3_0`1.<Execute>b__0()
   at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action)

任何机构都可以在这方面提供帮助吗?

最佳答案

回顾一下,我在尝试运行 dotnet CLI 命令时遇到了此错误。我发现的问题是 CLI 环境默认使用 .NET Core 2.0 版本的 dotnet 和 ef 命令,但我需要使用 .NET Core 1.1 版本因为这就是软件包版本的构建目标。

我发现(通过运行dotnet --info)环境中安装了多个版本的.NET Core SDK,并且路径默认指向最新版本。为了使用旧版本,我在解决方案根目录中添加了一个具有特定版本号的 global.json 文件。例如

{
  "sdk": {
    "version": "1.1.11"
  }
}

一切正常。

关于c# - Entity Framework Core 1.1.2 迁移异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49010490/

相关文章:

.net - .NET Core 2.0 中的 Websockets - 以 block 的形式接收消息

c# - 实现下拉列表模型的正确方法 .Net Core

javascript - Bootstrap 模式无法正确关闭

c# - 顺序访问异步套接字

c# - Windows 窗体安全 C#

c# - 关闭 Excel 工作簿

c# - System.Text.Json 中 Newtonsoft.Json DefaultValueHandling = DefaultValueHandling.Ignore 选项的等价物是什么

c# - Entity Framework Core 在 QueryType(数据库 View )上使用 Include

entity-framework-core - EF CORE如何将NVARCHAR转为VARCHAR

ASP.NET核心API : How to use MySQL