1

我有 Web.config:

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" requirePermission="false"/>
  </configSections>
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property name="connection.driver_class">NHibernate.Driver.OracleClientDriver</property>
      <property name="connection.connection_string">{old_connection}</property>
      <property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
      <property name="proxyfactory.factory_class">NHibernate.Bytecode.DefaultProxyFactoryFactory, NHibernate</property>
      <property name="show_sql">false</property>
      <property name="query.substitutions">true 1, false 0, yes 'Y', no 'N'</property>
    </session-factory>
  </hibernate-configuration>
</configuration>

我应用了一个转换。Web.Release.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform"
               xmlns:hib="urn:nhibernate-configuration-2.2">
  <configSections>
    <section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate" requirePermission="false"/>
  </configSections>
  <hib:hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <hib:session-factory>
      <hib:property xdt:Transform="Replace" xdt:Locator="Match(name)" name="connection.connection_string">{new_connection}</hib:property>
    </hib:session-factory>
  </hib:hibernate-configuration>
</configuration>

在Release中运行VS2012,不会发生转换。字符串不会被替换。可能是什么原因?

4

1 回答 1

2

转换不会发生,因为元素名称与您的基线不同Web.config。如果您删除hib命名空间,则会发生转换。

<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <session-factory>
      <property xdt:Transform="Replace" xdt:Locator="Match(name)" name="connection.connection_string">{new_connection}</property>
    </session-factory>
  </hibernate-configuration>
</configuration>

还有一点需要注意。如果您当前的配置是Release并且您正在通过 运行您的应用程序Visual Studio,则服务器将指向您项目的根目录。在根目录下,您将拥有Web.configWeb.Debug.config并且Web.Release.config服务器将获取通常的配置文件,无需转换(即Web.config)。

于 2013-07-17T12:33:53.653 回答