如何在appSettings部分中使用Web更改属性的值。配置转换

时间:2021-08-01 20:19:31

Is it possible to transform the following Web.config appSettings file:

是否有可能改变以下的网络。配置appSettings文件:

<appSettings>
    <add key="developmentModeUserId" value="00297022" />
    <add key="developmentMode" value="true" />
    /* other settings here that should stay */
</appSettings>

into something like this:

是这样的:

<appSettings>
    <add key="developmentMode" value="false" />
    /* other settings here that should stay */
</appSettings>

So, I need to remove the key developmentModeUserId, and I need to replace the value for the key developmentMode.

因此,我需要删除key developmentModeUserId,并替换key developmentMode的值。

3 个解决方案

#1


365  

You want something like:

你想要的东西:

<appSettings>
  <add key="developmentModeUserId" xdt:Transform="Remove" xdt:Locator="Match(key)"/>
  <add key="developmentMode" value="false" xdt:Transform="SetAttributes"
          xdt:Locator="Match(key)"/>
</appSettings>

See Also: Web.config Transformation Syntax for Web Application Project Deployment

参见:网络。用于Web应用程序项目部署的配置转换语法

#2


1  

If you want to make transformation your app setting from web config file to web.Release.config,you have to do the following steps. Let your web.config app setting file is this-

如果你想将你的应用设置从web配置文件转换为web. release。配置,您必须执行以下步骤。让你的网站。配置app设置文件是这样的。

<appSettings>
     <add key ="K1" value="Debendra Dash"/>
  </appSettings>

Now here is the web.Release.config for the transformation.

这是网络,发布。配置的转换。

<appSettings>
    <add key="K1" value="value dynamicly from Realease"
       xdt:Transform="SetAttributes"
          xdt:Locator="Match(key)"   
         />
  </appSettings>

This will transform the value of K1 to the new value in realese Mode.

这将在realese模式中将K1的值转换为新值。

#3


1  

Replacing all AppSettings

更换所有AppSettings

This is the overkill case where you just want to replace an entire section of the web.config. In this case I will replace all AppSettings in the web.config will new settings in web.release.config. This is my baseline web.config appSettings:

这是超杀情况,您只想替换web.config的整个部分。在这种情况下,我将替换web中的所有AppSettings。config将在web.release.config中新建设置。这是我的基线网。配置appSettings:

<appSettings>
  <add key="KeyA" value="ValA"/>
  <add key="KeyB" value="ValB"/>
</appSettings>

Now in my web.release.config file, I am going to create a appSettings section except I will include the attribute xdt:Transform=”Replace” since I want to just replace the entire element. I did not have to use xdt:Locator because there is nothing to locate – I just want to wipe the slate clean and replace everything.

现在在我web.release。配置文件,我将创建appSettings部分,除了我将包含属性xdt:Transform= " Replace ",因为我只想替换整个元素。我不需要使用xdt:Locator,因为没有什么可定位的——我只想把石板擦干净,把所有东西都替换掉。

<appSettings xdt:Transform="Replace">
  <add key="ProdKeyA" value="ProdValA"/>
  <add key="ProdKeyB" value="ProdValB"/>
  <add key="ProdKeyC" value="ProdValC"/>
</appSettings>

Note that in the web.release.config file my appSettings section has three keys instead of two, and the keys aren’t even the same. Now let’s look at the generated web.config file what happens when we publish:

注意在web.release中。配置文件我的appSettings部分有三个键,而不是两个键,键都不一样。现在让我们看看生成的web。配置文件当我们发布时发生了什么:

<appSettings>
   <add key="ProdKeyA" value="ProdValA"/>
   <add key="ProdKeyB" value="ProdValB"/>
   <add key="ProdKeyC" value="ProdValC"/>
 </appSettings>

Just as we expected – the web.config appSettings were completely replaced by the values in web.release config. That was easy!

正如我们所期望的——网络。配置appSettings被web中的值完全替换。发布配置。这很容易!

#1


365  

You want something like:

你想要的东西:

<appSettings>
  <add key="developmentModeUserId" xdt:Transform="Remove" xdt:Locator="Match(key)"/>
  <add key="developmentMode" value="false" xdt:Transform="SetAttributes"
          xdt:Locator="Match(key)"/>
</appSettings>

See Also: Web.config Transformation Syntax for Web Application Project Deployment

参见:网络。用于Web应用程序项目部署的配置转换语法

#2


1  

If you want to make transformation your app setting from web config file to web.Release.config,you have to do the following steps. Let your web.config app setting file is this-

如果你想将你的应用设置从web配置文件转换为web. release。配置,您必须执行以下步骤。让你的网站。配置app设置文件是这样的。

<appSettings>
     <add key ="K1" value="Debendra Dash"/>
  </appSettings>

Now here is the web.Release.config for the transformation.

这是网络,发布。配置的转换。

<appSettings>
    <add key="K1" value="value dynamicly from Realease"
       xdt:Transform="SetAttributes"
          xdt:Locator="Match(key)"   
         />
  </appSettings>

This will transform the value of K1 to the new value in realese Mode.

这将在realese模式中将K1的值转换为新值。

#3


1  

Replacing all AppSettings

更换所有AppSettings

This is the overkill case where you just want to replace an entire section of the web.config. In this case I will replace all AppSettings in the web.config will new settings in web.release.config. This is my baseline web.config appSettings:

这是超杀情况,您只想替换web.config的整个部分。在这种情况下,我将替换web中的所有AppSettings。config将在web.release.config中新建设置。这是我的基线网。配置appSettings:

<appSettings>
  <add key="KeyA" value="ValA"/>
  <add key="KeyB" value="ValB"/>
</appSettings>

Now in my web.release.config file, I am going to create a appSettings section except I will include the attribute xdt:Transform=”Replace” since I want to just replace the entire element. I did not have to use xdt:Locator because there is nothing to locate – I just want to wipe the slate clean and replace everything.

现在在我web.release。配置文件,我将创建appSettings部分,除了我将包含属性xdt:Transform= " Replace ",因为我只想替换整个元素。我不需要使用xdt:Locator,因为没有什么可定位的——我只想把石板擦干净,把所有东西都替换掉。

<appSettings xdt:Transform="Replace">
  <add key="ProdKeyA" value="ProdValA"/>
  <add key="ProdKeyB" value="ProdValB"/>
  <add key="ProdKeyC" value="ProdValC"/>
</appSettings>

Note that in the web.release.config file my appSettings section has three keys instead of two, and the keys aren’t even the same. Now let’s look at the generated web.config file what happens when we publish:

注意在web.release中。配置文件我的appSettings部分有三个键,而不是两个键,键都不一样。现在让我们看看生成的web。配置文件当我们发布时发生了什么:

<appSettings>
   <add key="ProdKeyA" value="ProdValA"/>
   <add key="ProdKeyB" value="ProdValB"/>
   <add key="ProdKeyC" value="ProdValC"/>
 </appSettings>

Just as we expected – the web.config appSettings were completely replaced by the values in web.release config. That was easy!

正如我们所期望的——网络。配置appSettings被web中的值完全替换。发布配置。这很容易!