2013-07-17 36 views
1

我的Web.config:變換的Web.config Hibernate配置VS 2012

<?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,轉換不會發生。該字符串未被替換。 可能是什麼原因?

回答

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.config,Web.Debug.configWeb.Release.config,服務器將接收通常的配置文件,而不進行轉換(即Web.config)。

+0

web.config沒有改變,命名空間沒有問題。但是你在這篇出版物中正在發生轉變。當我剛剛發佈時,它工作。 – ask125342