【问题标题】:Entity framework core 1.1.2 migration exceptionEntity Framework Core 1.1.2 迁移异常
【发布时间】:2018-02-27 13:59:51
【问题描述】:

我遇到了一些奇怪的异常。

我已经看到以下线程讨论了有关将 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)

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

【问题讨论】:

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


【解决方案1】:

回想起来,我在尝试运行 dotnet CLI 命令时遇到了这个错误。我发现的问题是 CLI 环境默认使用 .NET Core 2.0 版本的 dotnetef 命令,但我需要使用 .NET Core 1.1 版本因为这是构建软件包版本的依据。

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

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

一切正常。

【讨论】:

  • 我的版本是 2.0.0,我认为与安装的 sdks 不同。
【解决方案2】:

确保所有版本对齐。

<ItemGroup>
  <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.5" />
  <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.5" />
</ItemGroup>

<ItemGroup>
  <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet"
                          Version="1.1.5" />
</ItemGroup>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-10-27
    • 2018-11-05
    • 2020-03-09
    • 2017-02-06
    • 1970-01-01
    • 1970-01-01
    • 2017-05-16
    • 2018-03-20
    相关资源
    最近更新 更多