none
VS2010 web.config transformation not working on NHibernate section

    Question

  • My web.config transformation contains five transformation actions
    (see web.config.uat contents below).

    Only the first transformation,

    <strong><property name="connection.connection_string_name" xdt:Transform="Replace" xdt:Locator="Match(name)">FirstStandardDbConn</property></strong>
    <br/>
    
    

    fails, with the following warning from commandline MSBuild:

    "warning : No element in the source document matches '.configuration/hibernate-configuration'
    [<path>\<projname>.csproj]"

    I've tried this with different locators, but my impression is that MSBuild just does not 'see' the hibernate-configure section of the config file, perhaps because it is not aware of the namespace specified for it?

    web.uat.config file:

    <?xml version="1.0"?>
    
    <!-- For more information on using web.config transformation visit http://go.microsoft.com/fwlink/?LinkId=125889 -->
    
    <configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
     <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
      <session-factory name="ThisProjectConfig">
       <property name="connection.connection_string_name" xdt:Transform="Replace" xdt:Locator="Match(name)">FirstStandardDbConn</property>
      </session-factory>
     </hibernate-configuration>
    
     <connectionStrings>
      <add name="FirstStandardDbConn" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxx)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=xxx)));User Id=xxx;Password=xxx;" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
      <add name="SecondStandardDbConn" connectionString="Data Source=xxx;User Id=xxx;Password=xxx;Pooling=true" providerName="Oracle.DataAccess.Client" xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
     </connectionStrings>
    
     <system.web>
      <compilation xdt:Transform="RemoveAttributes(debug)" />
     </system.web>
    
     <appSettings>
      <add key="DBConfigPath" value="c:\dev\solution\project\web.config" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
     </appSettings>
    
    </configuration>
    

    Thursday, August 26, 2010 4:39 PM

Answers

  • I solved my error by removing the xmlns from the log4net element in the base Web.config, which has fixed the solution.  Would be interested to know if anyone else had a different solution to this problem that meant the namespace could still be included however.

     

     

    Friday, August 27, 2010 2:06 PM

All replies

  • Im getting a similliar problem with log4net.  I have the following transformation code

    <appender name="NEWLog" type="log4net.Appender.RollingFileAppender" xdt:Transform="Insert">
       <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%d{HH:mm:ss.fff} %-3p %message%n"/>
       </layout>
       <filter type="log4net.Filter.LevelRangeFilter">
        <levelMin value="INFO"/>
        <levelMax value="INFO"/>
       </filter>
       <param name="File" value="xxxxxx.log"/>
       <param name="RollingMode" value="Date"/>
       <param name="DatePattern" value="yyyyMMdd"/>
       <param name="AppendToFile" value="true"/>
      </appender>
    
    which is throwing an error saying 'No element in the source document matches /configuration/log4net/appender'
    Friday, August 27, 2010 9:34 AM
  • I solved my error by removing the xmlns from the log4net element in the base Web.config, which has fixed the solution.  Would be interested to know if anyone else had a different solution to this problem that meant the namespace could still be included however.

     

     

    Friday, August 27, 2010 2:06 PM
  • Hi rnewman1000,

    You could solve this problem by adding the log4net namespace to the transformation file:

     

    <configuration xmlns:log="urn:log4net-configuration" xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    

     

    In the log4net section you can use the xdt XML namespace. Note that visual studio reports two warnings about the xdt attributes that are not declared, but you can ignore those warnings.

     

    <log4net xmlns="urn:log4net-configuration" xdt:Transform="Replace" xdt:Locator="XPath(//log:log4net)">
    

     

    In the original .config file also use log4net with the log4net namespace.

     

    <log4net xmlns="urn:log4net-configuration">
    

     

    KR,

    Paul

    Thursday, October 21, 2010 6:52 AM
  • Found a proper solution here:

    http://www.jamescrowley.co.uk/2011/01/19/web-config-transformations-for-nhibernate/#comment-208


    Alex
    Tuesday, May 03, 2011 11:36 PM