【问题标题】:Your target project 'x' doesn't match your migrations assembly 'xx'. Either change your target project or change your migrations assembly您的目标项目“x”与您的迁移程序集“xx”不匹配。更改您的目标项目或更改您的迁移程序集
【发布时间】:2019-12-10 10:54:33
【问题描述】:

.net 核心 3.0。 我有一个 LibraryProject(SyWaterStandardLibrary),有一个 DbContext。当我构建新的 WebProject(WebApplicationTestLibrary) 并使用 LibraryProject。

启动:

  services.AddDbContext<LocalContext>(options =>
                options.UseSqlServer(Configuration.GetConnectionString("SMS"), 
                optionsBuilder => optionsBuilder.MigrationsAssembly("WebApplicationTestLibrary"))
               );

当我执行时:add-migration init -context localcontext

发生错误:您的目标项目“WebApplicationTestLibrary” 与您的迁移程序集“SyWaterStandardLibrary”不匹配。 更改您的目标项目或更改您的迁移程序集。

.net core 2.2 中不存在此异常。 请问有什么问题。

编辑 1: WebApplicationTestLibrary

SyWaterStandardLibrary

【问题讨论】:

  • 你检查过.net核心版本匹配吗??
  • 是的。我查过了。
  • 当我将启动项目和目标项目设置为 WebApplicationTestLibraryoptionsBuilder =&gt; optionsBuilder.MigrationsAssembly("SyWaterStandardLibrary")) 时,我得到了同样的错误,还有一个建议是用 WebApplicationTestLibrary 更改你的迁移程序集来解决问题 。确保启动项目、目标项目和 migrationsAssembly 相同。

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


【解决方案1】:

当您从 Visual Studio 中的包管理器控制台运行任何 Entity Framework Core 命令时,默认项目必须是您的迁移程序集SyWaterStandardLibrary。这是一张显示如何更改它的图片(这里,我的迁移程序集称为Model):

注意这里和启动项目不一样。

【讨论】:

  • 感谢您的回复。但我只有一个选项,只有 WebApplicationTestLibrary,选项中没有 SyWaterStandardLibrary。
  • WebApplicationTestLibrary 使用编译后的DLL文件参考
猜你喜欢
  • 2016-09-26
  • 1970-01-01
  • 2020-08-23
  • 1970-01-01
  • 2017-01-21
  • 1970-01-01
  • 2019-09-06
  • 2013-09-27
  • 1970-01-01
相关资源
最近更新 更多