web.config transform not working

In an MVC application I have a web.config that is setup for my development environment, and I have a transform file that needs to insert a new WCF service endpoint, however it is adding it in the wrong place so I think I have missed something.

I have cut down on the config file to show only what is needed.

I have the normal web.config as follows:

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

I then have the transform file as follows:

<services>

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

</services>

I expected this to add the new endpoint in the "AuthenticationHost" service, but it adds it to the first service "ReportDataHost".

Any ideas what I am missing?

Answers


Transforms only use tags by default, not attributes, so even though you have name="Core.AuthenticationHost" in your transform, it is being ignored and only matching on the Service tag, using the first Service tag it finds.

Add a locator to the <service> tag so that it knows which one to use (instead of just using the first). The Locator is an attribute on the tag: xdt:Locator="Match(attribute1,attribute2,...)". In this case, you want to match on the name attribute.

Your corrected Transform will look like this:

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

More information is available on MSDN's Transform Syntax page.


Need Your Help

Getting and storing the path of file in asp.net 5

asp.net asp.net-core asp.net-core-mvc

In previous version of asp.net the HostingEnvironment had MapPath method to get and store the path of the file but in ASP.net 5 I can't use it.

What's the difference between isset() and array_key_exists()?

php

How do the following two function calls compare: