web.config转换无法正常工作

时间:2012-07-17 14:17:35

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

在MVC应用程序中,我有一个为我的开发环境设置的web.config,我有一个转换文件,需要插入一个新的WCF服务端点,但是它将它添加到错误的位置所以我想我错过了什么。

我已经减少配置文件以仅显示所需内容。

我有正常的web.config,如下所示:

<services>
  <!-- Report Service -->
  <service name="Core.ReportDataHost">
    <endpoint name="ReportDataHost" address="..." binding="customBinding" contract="..."/>
  </service>

  <!-- Authentication Service -->
  <service name="Core.AuthenticationHost">
    <endpoint name="AuthenticationHost" address="..." binding="customBinding" contract="..."/>
  </service>

</services>

然后我将变换文件如下:

<services>

  <service name="Core.AuthenticationHost">
    <endpoint xdt:Transform="Insert" address="" binding="customBinding" contract="..." />
  </service>

</services>

我希望这会在“AuthenticationHost”服务中添加新端点,但会将其添加到第一个服务“ReportDataHost”中。

我缺少什么想法?

1 个答案:

答案 0 :(得分:1)

默认情况下,变换仅使用标记,而不是属性,因此即使变换中有name =“Core.AuthenticationHost”,它也会被忽略,并且仅使用它找到的第一个Service标记在Service标记上匹配。 / p>

<service>标记中添加一个定位符,以便它知道要使用哪个(而不是仅使用第一个)。定位器是标记的一个属性:xdt:Locator="Match(attribute1,attribute2,...)"。在这种情况下,您希望匹配name属性。

您更正后的变换将如下所示:

<services>
  <service name="Core.AuthenticationHost" xdt:Locator="Match(name)">
    <endpoint xdt:Transform="Insert" address="" binding="customBinding" contract="..." />
  </service>
</services>

有关详情,请参阅MSDN's Transform Syntax page