简体   繁体   中英

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. For instance "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. My approach for now is to write it to the web.config, and the let the application read that value on demand. 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:

<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:

  • Target Files: web.config
  • Token Prefix: #{
  • Token Suffix: }#

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM