实体框架迁移Azure DevOps发布管道 [英] Entity Framework Migration Azure DevOps Release Pipeline

本文介绍了实体框架迁移Azure DevOps发布管道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Azure DevOps发布管道上运行迁移.因为我想在每个发行版上自动运行数据库脚本.我的发布管道没有源代码,我只有编译的DLL.

I'm trying to run migration on Azure DevOps Release Pipeline. Because I want to run my DB scripts automatically on every release. My release pipeline does not have source code, I just have compiled DLLs.

当我在本地计算机上执行此命令时,它成功运行.如何转换此命令,以便可以与DLL一起使用.

When I execute this command on my local machine, it runs successfully. How can I convert this command so I can use it with DLLs.

dotnet ef database update --project MyEntityFrameworkProject --context MyDbContext --startup-project MyStartupProject

推荐答案

如果您不想将源代码包含在工件中,则可以使用以下脚本:

If you don't want to include your source code with the artifacts you can use the following script:

set rootDir=$(System.DefaultWorkingDirectory)\WebApp\drop\WebApp.Web
set efPath=C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.entityframeworkcore.tools\2.1.1\tools\netcoreapp2.0\any\ef.dll
dotnet exec --depsfile "%rootDir%\WebApp.deps.json" --additionalprobingpath %USERPROFILE%\.nuget\packages --additionalprobingpath "C:\Program Files\dotnet\sdk\NuGetFallbackFolder" --runtimeconfig "%rootDir%\WebApp.runtimeconfig.json" "%efpath%" database update --verbose --prefix-output --assembly "%rootDir%\AssemblyContainingDbContext.dll" --startup-assembly "%rootDir%\AssemblyContainingStartup.dll" --working-dir "%rootDir%"

事实证明,您可以像下面的示例一样使用未记录的dotnet exec命令(假设Web应用程序称为WebApp):

It turns out you can get away with the undocumented dotnet exec command like the following example (assuming the web application is called WebApp):

请注意,必须将此运行命令行任务的工作目录(隐藏在高级"下)设置为工件所在的位置(上述rootDir).

Note that the Working Directory (hidden under Advanced) of this run command line task must be set to where the artifacts are (rootDir above).

另一种选择是安装构建并安装发布工具扩展,并使用从DLL部署实体框架核心迁移"任务.

Another option is to install Build & Release Tools extension and use the "Deploy Entity Framework Core Migrations from a DLL" task.

您可以阅读更多信息这里此处此处.

You can read more info here, here and here.

这篇关于实体框架迁移Azure DevOps发布管道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆