【问题标题】:What happened to CSharpMigrationsGenerator and SqlServerMigrationsSqlGeneratorCSharpMigrationsGenerator 和 SqlServerMigrationsSqlGenerator 发生了什么
【发布时间】:2022-01-10 04:02:21
【问题描述】:

将现有项目从 EF Core 5 升级到 EF Core 6 后,某些自定义项将不再编译,特别是对 CSharpMigrationsGenerator 和 SqlServerMigrationsSqlGenerator 类的自定义项。尽管命名空间是正确的,但 Visual Studio 强调了对它们的引用,并且似乎不知道我在说什么。查看 EF Core 源代码,类在它们应该在的地方,为什么我在我的项目中看不到它们?

【问题讨论】:

    标签: entity-framework-core ef-core-6.0


    【解决方案1】:

    这是 NuGet 更新包引用的副作用。 Microsoft.EntityFrameworkCore.Migrations.Design 命名空间来自 Microsoft.EntityFrameworkCore.Design 包,它希望像分析器一样安装自己。

    更新参考后,您的 csproj 文件将如下所示:

    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
    </PackageReference>
    

    这是不正确的。这就是您引用分析器的方式。它使该包中的代码可用于 Visual Studio,但不能用于您的代码。你想要的是一个普通的旧包参考,像这样:

    <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.0" />
    

    修复您的 csproj 文件将使这些类再次可用于您的代码。

    【讨论】:

    猜你喜欢
    • 2014-10-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-28
    • 2014-02-28
    • 2010-10-02
    • 2020-03-14
    • 2011-04-09
    相关资源
    最近更新 更多