如何使用 web.config 转换在 APP 设置部分插入新密钥

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

我想在应用程序设置部分插入新的键值,其他键值应保持不变。

下面是我的源配置 <

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

`

我的转换配置文件如下所示:

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

我建议你关注 this post 但从我上面看到的

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

您应该将 xdt:Transform="SetAttributes" 更改为 xdt:Transform="Insert"