0

I have a file called entlib.config like below:

<loggingConfiguration name="Logging Application Block" tracingEnabled="true"
  defaultCategory="General" logWarningsWhenNoCategoriesMatch="true">
<listeners >
  <add name="Email TraceListener" toAddress="axx.xxx@xxx.com" fromAddress="axx.xxx@xxx.com" subjectLineStarter="xxxxx " subjectLineEnder="" smtpServer="xxx.com" smtpPort="xxx" formatter="Text Formatter"

Now,in this file needs to replace fromAddress, toAddress and subjectLineStarter attribute has a variables groups for azure pipeline... how to do this change ? can we do have an option to change any config file that has been created as xml to change more than one attribute ?

Ram
  • 1
  • 1

1 Answers1

0

To replace the vaules in **.config file with the variables in Variable group, you can try the following methods:

1.You can use the XML variable substitution option in the Azure App service deploy task or IIS deploy task.

enter image description here

For more detailed steps, refer to this doc: XML variable substitution

2.You can use PowerShell script to modify attributes in the config file.

Here is the PowerShell script sample:

$entlibConfig = 'path\entlib.config'

Function updateConfig($config) 
{ 
$doc = (Get-Content $config) -as [Xml]
$root = $doc.get_DocumentElement();
$activeConnection = $root.loggingConfiguration.listeners.SelectNodes("add"); #You need to define the correct location of the parameter
$activeConnection.SetAttribute("fromAddress", "$(fromAddress)");
$activeConnection.SetAttribute("toAddress ", "$(toAddress )“);
$activeConnection.SetAttribute("subjectLineStarter ", "$(subjectLineStarter )“);
$doc.Save($config)
} 

updateConfig($entlibConfig)

3.When you add the mark: #{..}# in entlib.config file, you can try to use the Replace Token task from Replace Tokens Extension.

Refer to the example in this ticket:How to perform XML Element substitution in web.config using Replace Tokens?

Kevin Lu-MSFT
  • 20,786
  • 3
  • 19
  • 28