如何在SQL Server数据库项目中引用已定义的变量? [英] How do you reference defined variables in a SQL Server Database Project?

查看:257
本文介绍了如何在SQL Server数据库项目中引用已定义的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了许多关于此的问题,例如:

I've read many questions on this such as:

如何根据部署配置文件运行不同的SSDT之前和之后的发布脚本

我想要实现的是一种基于要部署到的环境定义一组脚本的方法.这个想法是将环境作为SQLCMD变量作为azure-devops管道的一部分传递到名为$(ServerName)的变量中,该变量已在sql server数据库项目中的默认属性为"DEV"的属性下设置. .

What I'm trying to achieve is a way of defining a set of scripts based on the environment being deployed to. The idea is that the environment is passed in as a SQLCMD variable as part of the azure-devops pipeline into a variable called $(ServerName), which I've setup in the sql server database project under properties with a default of 'DEV'.

然后将其用于后期部署脚本中,如下所示:

This is then used in the post deployment script like this:

:r .\PostDeploymentScripts\$(ServerName)\index.sql

因此,这应该基于$(ServerName)变量选择正确的index.sql文件.通过发布$ {ServerName)变量并输入'QA'并生成脚本进行测试时,它仍显示'DEV'脚本.但是,脚本顶部显示该变量已正确设置:

This should therefore pick up the correct index.sql file based on the $(ServerName) variable. When testing this by publishing and entering 'QA' for the $(ServerName) variable and generating the script it was still displaying the 'DEV' scripts. However, the top of the script showed the variable had been set correctly:

如何获取部署后脚本以正确引用$(ServerName)变量,以便可以动态设置正确的引用路径?

How do I get the post deployment script to reference the $(ServerName) variable correctly so I can dynamically set the correct reference path?

推荐答案

与这篇不错的文章相反: https://stackoverflow.com/a/54482350/11035005 ,似乎在编译时对:r指令进行了评估,并在甚至对xml配置文件进行评估之前将其插入了DACPAC中,因此无法按照说明进行操作.

Contrary to this nice post: https://stackoverflow.com/a/54482350/11035005 , it appears that the :r directive is evaluated at compile time and inserted into the DACPAC before the xml profiles are even evaluated so this is not possible as explained.

使用的值是构建配置中的默认值或局部值,只能从那里进行控制.

The values used are the defaults or locals from the build config and can only be controlled from there.

这篇关于如何在SQL Server数据库项目中引用已定义的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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