31

I have the following in my app.config file. I am using Slow Cheetah and just want to replace replace configuration/entityFramework/defaultConnectionFactory/parameters/parameter so it points to a diff server. ie value-data source=some-server....

    <?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
  </appSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="data source=.;Integrated Security=SSPI;Initial Catalog=SomeDb;MultipleActiveResultSets=true" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
  <system.web>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
</configuration>

I have tried to the following in the app.config.release but to no avail.

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="data source=dbserver;Integrated Security=SSPI;Initial Catalog=someDb;MultipleActiveResultSets=true" 
                   xdt:Transform="Replace" 
                   xdt:Locator="XPath(configuration/entityFramework/defaultConnectionFactory/parameters/parameter)" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>

also tried xdt:Locator="Match(parameter)" and xdt:Locator="XPath(parameter)

and many more but can't get it to work.

Concrete Gannet
  • 551
  • 4
  • 11
etoisarobot
  • 7,684
  • 15
  • 54
  • 83

1 Answers1

57

Ok. I feel a little silly but the solution is that I didn't need to specify a xdt:Locator.

If I just leave the App.Release.Config like this it will replace matching entry.

 <parameter value="data source=dbserver;Integrated Security=SSPI;Initial Catalog=someDb;MultipleActiveResultSets=true" 
               xdt:Transform="Replace"/>
  </parameters>
etoisarobot
  • 7,684
  • 15
  • 54
  • 83
  • 12
    Don't feel silly, the documentation isn't at all clear about it! Thanks for posting your findings. – Tobias J May 01 '14 at 15:54
  • I had the same issue with . That one doesn't have a name to use for matching so I just used your method of replace. – Dan P Dec 07 '16 at 16:28
  • @TobyJ - The documentation may not be clear but when you think about it, the locator is something that helps to tune the default location match. If you don't give anything, the hierarchy of elements will be used. (if it didn't you'd have to give xdt:Locator at every ancestor element in your transform along the chain) – arviman Jun 12 '17 at 09:05