如何有条件地在 ssdt 部署后脚本中包含大型脚本? [英] How can I conditionally include large scripts in my ssdt post deployment script?

查看:27
本文介绍了如何有条件地在 ssdt 部署后脚本中包含大型脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的 SSDT 项目中,我们有一个巨大的脚本,其中包含许多用于从旧系统导入数据的 INSERT 语句.使用 sqlcmd 变量,我希望能够有条件地将文件包含到部署后脚本中.

In our SSDT project we have a script that is huge and contains a lot of INSERT statements for importing data from an old system. Using sqlcmd variables, I'd like to be able to conditionally include the file into the post deployment script.

我们目前正在使用 :r 语法,其中包含内联脚本:

We're currently using the :r syntax which includes the script inline:

IF '$(ImportData)' = 'true'
BEGIN
  :r .\Import\OldSystem.sql
END

这是一个问题,因为无论 $(ImportData) 是真还是假,脚本都被内联包含在内,而且文件太大以至于减慢了构建速度下降了大约 15 分钟.

This is a problem because the script is being included inline regardless of whether $(ImportData) is true or false and the file is so big that it's slowing the build down by about 15 minutes.

是否有另一种方法可以有条件地包含此脚本文件,以免减慢构建速度?

Is there another way to conditionally include this script file so it doesn't slow down the build?

推荐答案

我最终混合使用了我们的构建工具 (Jenkins) 和 SSDT 来完成此任务.这就是我所做的:

I ended up using a mixture of our build tool (Jenkins) and SSDT to accomplish this. This is what I did:

  1. 为写入文本文件的每个特定于环境的 Jenkins 作业添加了构建步骤.我要么编写包含导入文件的 SQLCMD 命令,要么根据用户选择的构建参数将其留空.
  2. 通过 :r 在部署后脚本中包含新的文本文件.
  1. Added a build step to each environment-specific Jenkins job that writes to a text file. I either write a SQLCMD command that includes the import file or else I leave it blank depending on the build parameters the user chooses.
  2. Include the new text file in the Post Deployment script via :r.

就是这样!我还使用相同的方法根据应用程序版本选择要包含在项目中的部署前和部署后脚本,不同之处在于我从代码中获取版本号并使用 VS 中的预构建事件将其写入文件在构建工具中.(我还将文本文件名添加到 .gitignore 以便它不会被提交)

That's it! I also use this same approach to choose which pre and post deploy scripts to include in the project based on the application version, except that I grab the version number from the code and write it to the file using a pre-build event in VS instead of in the build tool. (I also added the text file name to .gitignore so it doesn't get committed)

这篇关于如何有条件地在 ssdt 部署后脚本中包含大型脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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