[英]Set Release name in web.config when deploying with Azure DevOps
We're building and deploying our application to 30 separate web apps every night, and I would like to know which release every web app is currently on.我们每晚都在构建我们的应用程序并将其部署到 30 个单独的 web 应用程序,我想知道每个 web 应用程序当前在哪个版本上。 For instance "Release-12345".
例如“Release-12345”。
The value exists in the release variable Release.ReleaseName
from Release variables (MS doc) , but I have no idea on how to make my pipeline use that value.该值存在于发布变量 (MS doc)的发布变量
Release.ReleaseName
中,但我不知道如何让我的管道使用该值。 My approach for now is to write it to the web.config, and the let the application read that value on demand.我现在的方法是将它写入 web.config,然后让应用程序按需读取该值。 But if there's another, more efficient or "correct" way of doing it, I'm open for anything.
但如果有另一种更有效或“正确”的方法,我愿意接受任何事情。
It's a classic usage of "replace tokens" tasks, there are many extensions in the marketplace , the most popular is Replace Tokens .这是“替换令牌”任务的经典用法, 市场上有很多扩展,最受欢迎的是替换令牌。
You need to add a placeholder in the web.config
, for example:您需要在
web.config
中添加一个占位符,例如:
<add key="Release_number" value="#{Release_number}#" />
In the release variables you need to add a variable Release_number
with the value $(Release.ReleaseName)
, and add the Replace Tokens task in your release pipeline with configuration of:在发布变量中,您需要添加一个值为
$(Release.ReleaseName)
的变量Release_number
,并在您的发布管道中添加 Replace Tokens 任务,配置如下:
web.config
web.config
#{
#{
}#
}#
Now, the task will search inside the web.config
file strings that match the pattern and will replace them with the value from the release variables.现在,该任务将在
web.config
文件中搜索与模式匹配的字符串,并将其替换为发布变量中的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.