使用Web.Config转换插入多个项目

时间:2012-10-09 22:21:09

标签: asp.net web-config web-config-transform

我有一个引用了很多WCF服务的C#项目。对于本地测试,我想替换身份标签的内容,以便它接受在localhost上运行的任何内容。

以下转换有效,但仅在第一个匹配位置插入dns元素。所以,如果我引用了5个端点,则会有一个dns标记,其他的都会有空的标识元素。

<system.serviceModel>
    <client>
      <endpoint>
        <identity>
          <dns xdt:Transform="Insert" value="localhost"/>
          <userPrincipalName xdt:Transform="RemoveAll" value="someIdentity" />
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>

如何更改所有匹配元素,而不仅仅是第一个?

1 个答案:

答案 0 :(得分:2)

使用xdt:Locator属性定义XPath表达式,以匹配要插入的所有<identity>元素。

  <system.serviceModel>
    <client>
      <endpoint>
        <identity xdt:Locator="XPath(//identity)">
          <dns xdt:Transform="Insert" value="localhost"/>
          <userPrincipalName xdt:Transform="RemoveAll"/>
        </identity>
      </endpoint>
    </client>
  </system.serviceModel>