279

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

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

4

4 に答える 4

483

あなたは次のようなものが欲しいです:

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

関連項目:WebアプリケーションプロジェクトデプロイメントのWeb.config変換構文

于 2012-06-14T15:19:22.367 に答える
2

私は変換が必要以上の情報を持つのは好きではありません。そのため、キーを再度説明する代わりに、条件意図を簡単に説明します。少なくとも IMO では、このようにすると、意図がずっと簡単にわかります。また、読者に示すためにすべてのxdt属性を最初に配置しようとしています。これらは変換であり、新しいものは定義されていません。

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

上記では、最初の要素が要素を削除していることをより簡単に確認できます。2つ目は属性の設定です。ここで定義した属性を設定/置換します。この場合、単純に に設定さvaluefalseます。

于 2019-12-10T20:14:06.513 に答える