how to update a section in Web.Config using transforms?

58 Views Asked by At

In my Web.Config I have the following

<configuration>
  <configSections>
   /*some code*/
  </configSections>
  <appSettings>
    <add key="KeyName" value="KeyValue"/>
  </appSettings>
</configuration>

And I have used below code when deploying a web application project.

{
  "QA": {
    "ConfigChanges": [
      {
        "KeyName": "/configuration/appSettings/add[@key='KeyName']",
        "Attribute": "value",
        "Value": "NewKeyValue"
      }
    ]
  }
}

Above code finds the configuration with appkey name and overwrites it. But how do we configure if it doesn't have any key, like smtp settings?

<system.net>
  <mailSettings>
    <smtp from="" deliveryMethod="Network">
      <network host="smtp.gmail.com" port="57" defaultCredentials="true"  />
    </smtp>
  </mailSettings>
</system.net>

I tried like below like using key, but I got the error.

{
 "KeyName":"/configuration/system.net/mailSettings/smtp/network[@defaultCredentials='true']",
 "Attribute": "host",
 "Value": "test.com"
}

Failure while updating port of /configuration/system.net/mailSettings/smtp/network[@defaultCredentials='true']: 25

Can you please help me on this.

0

There are 0 best solutions below