Search code examples
asp.netazure-devopsweb-configweb.config-transformxdt-transform

How to Insert new Key in APP settings section with web.config Transformation


I would like to insert new key value in app settings section and other key values should remains same.

Below is my source config <

add key="UserName" value="Apple" /> 
    <add key="Main.ConnectionString" value="Data Source=testingdevmachine;Persist Security Info=false;User ID=test;Password=test;Validate Connection=true;" />
        <add key="CTCredentials01" value="userid@test|password@test&12|server@https://test/" />
        <add key="WFCredentials01" value="userid@test|password@Mango| server@https://test/ />

`

My Transform config file is looks like:

         <add key="CTCredentials01" value="userid@test123|password@test&12|server@https://test/" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
    <add key="WFCredentials01" value="userid@test123|password@Mango| server@https://test/" 
  xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/> 
    <add key="WFCredentials03" value="userid@test123|password@Mango| server@https://test/" 
  xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/> 
<add key="UserName" value="Nick"
        xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>

Now, from above transform config add key="WFCredentials03" this key does not have in my source config file so how can I add here in my transform config file?


Solution

  • I would recommend you follow this post but from what I see above

    <add key="WFCredentials03" value="userid@test123|password@Mango| server@https://test/" 
      xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/> 
    

    you should change xdt:Transform="SetAttributes" to xdt:Transform="Insert"