Entity Framework 6 .net Framework 迁移/包管理控制台 - 您如何 运行 这些在 Azure 管道中?

Entity Framework 6 .net Framework Migrations / Package Management Console - How Do You Run These In An Azure Pipeline?

我正在设置一个 Azure 发布管道,我需要在发布过程中执行任何待处理的数据库迁移。

我已经在互联网上搜索了一个多小时,我能找到的所有内容都是关于 dotnet Core 的,而数据库是 .Net Framework 上的 EF6,而不是 dotnet Core(我之前为 Core 做过几次) .

在我看来,问题是 EF6 使用 Visual Studio 内置的包管理器控制台工作——这在 Azure Pipeline 中不存在;这是一个 Visual Studio 怪异。

在我的脑海中似乎有几种方法可以给这只猫剥皮,但我不知道如何在管道的上下文中从它们中的任何一个开始...

选项 1:运行 管道中的迁移 - 但是...如何?

选项 2:SQL 脚本 - 需要 运行 包管理器生成它们,这样它们就可以 运行(如果我可以在管道上做到这一点,那么我会无论如何只是运行所以这些必须在本地创建并使用代码提交,作为解决方案IMO有点落后)

选项 3:编写控制台应用程序 - 我真的必须这样做吗??

你可以试试Entity Framework Migration Extensions.

This task allows a Build / Release to provide database connection parameters and execute an Entity Framework 6 migration against the database.

  1. Build your project to an output folder and include the migrate.exe executable that comes with Entity Framework 6.
  2. Create an automated build that packages up your files and makes them accessible during a Release.
  3. Create a Release definition for the relevant Build
  4. Add an EF6 Migration task. Once that task is added to an environment within the release, you'll need to enter the appropriate parameters to configure it. All file path parameters should be within the file system for the build, none of them are for TFS source control paths.

你也可以检查这个article

这里的答案是使用 ef6.exe 命令行工具并确保它随您的构建一起提供。

在 Microsoft 更新不存在的文档之前,这对这里的任何人都有用:http://github.com/dotnet/EntityFramework.Docs/issues/1740 - 这包含一个 table 以及两者之间的一种转换矩阵。