31

我的 app.config 文件中有以下内容。我正在使用 Slow Cheetah,只想替换 configuration/entityFramework/defaultConnectionFactory/parameters/parameter 以便它指向差异服务器。即价值数据源=一些服务器....

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

我在 app.config.release 中尝试过以下操作,但无济于事。

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

也尝试xdt:Locator="Match(parameter)"xdt:Locator="XPath(parameter)

还有更多,但无法正常工作。

4

1 回答 1

57

好的。我觉得有点傻,但解决方案是我不需要指定 xdt:Locator。

如果我像这样离开 App.Release.Config 它将替换匹配的条目。

 <parameter value="data source=dbserver;Integrated Security=SSPI;Initial Catalog=someDb;MultipleActiveResultSets=true" 
               xdt:Transform="Replace"/>
  </parameters>
于 2013-03-24T16:44:57.337 回答