'How to Update the .config file using Azure DevOps "Update config" Task

I want to Update the Web.config file using Azure DevOps Release Pipeline. I am using [Update Config][1] Task from MarketPlace. [1]: https://marketplace.visualstudio.com/items?itemName=digitalmedia34.updateconfig

Here Is the Web.config File

<!-- Some Contents -->
<configuration>

  <appSettings>
    <add key="Setting1" value="local setting"/>
    <add key="CommonSetting" value="local common setting"/>
  </appSettings>
  
  <connectionStrings>
    <add name="MyDB"
         connectionString="Data Source=LocalSQLServer;Initial Catalog=MyReleaseDB;User ID=xxxx;Password=xxxx" />
  </connectionStrings>
  
  <system.web>
    <compilation debug="true" targetFramework="4.7.2"/>
    <httpRuntime targetFramework1="4.7.2"/>
  </system.web>
  
</configuration>

I am able to change the value of some configuration by adding variables like [Variables]
[2]: https://i.stack.imgur.com/uq85Y.png

My Question is how can I change the values of Nested Property. For Example if I want to change the targetFramework in

  <system.web>
    <compilation debug="true" targetFramework="4.7.2"/>
    <httpRuntime targetFramework1="4.7.2"/>
  </system.web>

Please let me know how can I update these values

Thanks in advance



Solution 1:[1]

How to Update the .config file using Azure DevOps "Update config" Task

You could use the task Replace Tokens to update the key's values,

the format of variable in .config file is #{TestVersion}#:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

  <appSettings>
    <add key="Setting1" value="local setting"/>
    <add key="CommonSetting" value="local common setting"/>
  </appSettings>
  
  <connectionStrings>
    <add name="MyDB"
         connectionString="Data Source=LocalSQLServer;Initial Catalog=MyReleaseDB;User ID=xxxx;Password=xxxx" />
  </connectionStrings>
  
  <system.web>
    <compilation debug="true" targetFramework="#{TestVersion}#"/>
    <httpRuntime targetFramework1="#{TestVersion}#"/>
  </system.web>
  
</configuration>

Use Replace Tokens task to update the key's values:

enter image description here

And define the key's values on the Variables.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Leo Liu-MSFT