[英]Entity Framework 6 .net Framework Migrations / Package Management Console - How Do You Run These In An Azure Pipeline?
I am setting up an Azure Release Pipeline and I need to execute any pending DB Migrations as part of the release.我正在设置 Azure 发布管道,作为发布的一部分,我需要执行任何挂起的数据库迁移。
I have been scouring the internet for over an hour and everything I can find is about dotnet Core, while the database is EF6 on .Net Framework, not dotnet Core (I've done this several times before for Core).我已经在互联网上搜索了一个多小时,我能找到的所有内容都是关于 dotnet Core,而数据库是 .Net Framework 上的 EF6,而不是 dotnet Core(我之前为 Core 做过几次)。
The problem, as I see it, is that EF6 works using Visual Studio's built in Package Manager Console - This just doesn't exist in an Azure Pipeline;在我看来,问题在于 EF6 使用 Visual Studio 的内置包管理器控制台工作——这在 Azure Pipeline 中不存在; It's a Visual Studio weirdness.
这是 Visual Studio 的怪异之处。
There seems to be several ways I can skin this cat, in my head, but I can't figure out how to start with either of them within the context of the pipeline...在我的脑海里,似乎有几种方法可以给这只猫剥皮,但我无法弄清楚如何在管道的上下文中从它们中的任何一个开始......
OPTION 1: Run the Migrations on the Pipeline - but... how?选项 1:在管道上运行迁移 - 但是......如何?
OPTION 2: SQL Scripts - Requires running the Package Manager to generate them so they can be run (if I could do that on the pipeline then I'd just run it anyway so these would have to be created locally and committed with the code which is somewhat backward as a solution IMO)选项 2:SQL 脚本 - 需要运行包管理器来生成它们,以便它们可以运行(如果我可以在管道上这样做,那么无论如何我都会运行它,所以这些必须在本地创建并与代码一起提交)作为解决方案 IMO 有点落后)
OPTION 3: Write a console app - Do I really have to do this??选项 3:编写控制台应用程序 - 我真的必须这样做吗?
You can try Entity Framework Migration Extensions .您可以尝试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.
此任务允许构建/发布提供数据库连接参数并针对数据库执行 Entity Framework 6 迁移。
- Build your project to an output folder and include the migrate.exe executable that comes with Entity Framework 6.
将项目构建到输出文件夹并包含 Entity Framework 6 附带的 migrate.exe 可执行文件。
- Create an automated build that packages up your files and makes them accessible during a Release.
创建一个自动构建来打包您的文件并使其在发布期间可以访问。
- Create a Release definition for the relevant Build
为相关构建创建发布定义
- Add an EF6 Migration task.
添加 EF6 迁移任务。 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.
所有文件路径参数都应该在构建的文件系统内,它们都不是用于 TFS 源控制路径。
The answer here is to use the ef6.exe command line tool and make sure it gets shipped with your build.这里的答案是使用 ef6.exe 命令行工具并确保它随您的构建一起提供。
This could be useful to anyone here until Microsoft update the non-existent docs: http://github.com/dotnet/EntityFramework.Docs/issues/1740 - This contains a table with a kind of translation matrix between the two.在 Microsoft 更新不存在的文档之前,这对这里的任何人都可能有用: http : //github.com/dotnet/EntityFramework.Docs/issues/1740 - 这包含一个表,其中包含一种两者之间的转换矩阵。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.