Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

web.config transforms in alternate namespaces

I have a web config (truncated to show the important bits) like so:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
        <section name="nhs-configuration" type="NHibernate.Search.Cfg.ConfigurationSectionHandler, NHibernate.Search" requirePermission="false" />
    </configSections>
    <nhs-configuration xmlns="urn:nhs-configuration-1.0">
        <search-factory>
            <property name="hibernate.search.default.directory_provider">NHibernate.Search.Store.FSDirectoryProvider, NHibernate.Search</property>
            <property name="hibernate.search.default.indexBase">C:\files\FTIndex</property>
            <property name="hibernate.search.default.indexing_strategy">event</property>
        </search-factory>
    </nhs-configuration>
    <nlog
        xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        internalLogFile="c:\temp\nlogInternal.log"
        internalLogLevel="Info"
        internalLogToConsole="true">
        <targets>
            <target
                xsi:type="Database"
                name="db"
                keepConnection="false"
                useTransactions="true"
                connectionStringName="MyConnString"
                dbProvider="Npgsql"
                commandText="insert into logs (timestamp, thread, severity, source, message, exception, username) values (now(), :thread, :severity, :source, :message, :exception, :username);">
                <parameter name="thread" layout="${threadid}" />
                <parameter name="severity" layout="${uppercase:${level}}" />
                <parameter name="source" layout="${logger}" />
                <parameter name="message" layout="${message}" />
                <parameter name="exception" layout="${exception:format=type,message,method:maxInnerExceptionLevel=10}" />
                <parameter name="username" layout="${aspnet-user-identity}" />
            </target>
            <target xsi:type="Debugger" name="outputWindow" layout="${uppercase:${level}} ${aspnet-user-identity} ${message} ${exception:format=type,message,method:maxInnerExceptionLevel=10}"/>
        </targets>
        <rules>
            <logger name="*" minlevel="Trace" writeTo="outputWindow" />
            <logger name="*" minlevel="Debug" writeTo="db" />
        </rules>
    </nlog>
</configuration>

My transform file looks like this:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <nhs-configuration>
        <search-factory>
            <property name="hibernate.search.default.indexBase" xdt:Locator="Match(name)" xdt:Transform="Replace">/var/ftindex</property>
        </search-factory>
    </nhs-configuration>
    <nlog
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        internalLogFile="/var/log/nlogInternal.log"
        internalLogLevel="Warn"
        internalLogToConsole="false"
        xdt:Transform="SetAttributes(internalLogFile,internalLogLevel,internalLogToConsole)">
        <targets>
            <target
                name="db"
                keepConnection="true"
                useTransactions="false"
                xdt:Locator="Match(name)"
                xdt:Transform="SetAttributes(keepConnection,useTransactions)"
                >
                <parameter name="thread" layout="${threadid}" />
                <parameter name="severity" layout="${uppercase:${level}}" />
                <parameter name="source" layout="${logger}" />
                <parameter name="message" layout="${message}" />
                <parameter name="exception" layout="${exception:format=type,message,method:maxInnerExceptionLevel=10}" />
                <parameter name="username" layout="${aspnet-user-identity}" />
            </target>
            <target name="outputWindow" xdt:Locator="Match(name)" xdt:Transform="Remove" />
        </targets>
        <rules>
            <logger name="*" minlevel="Debug" writeTo="db" />
            <logger writeTo="outputWindow" xdt:Locator="Match(writeTo)" xdt:Transform="Remove" />
        </rules>
    </nlog>
</configuration>

Now, all parts of my web.config file transform properly upon publish except these two sections. My hunch is this has something to do with some kind of xml namespace conflict, but it could be something else entirely I guess.

Why won't these sections transform? They are being completely ignored and are ending up in the published web.config totally unchanged.

like image 277
Jeremy Holovacs Avatar asked Jan 15 '23 21:01

Jeremy Holovacs


1 Answers

Turns out the answer is pretty simple: just remove the default namespace declarations from the two nodes.

In this manner, you lose the nifty Intellisense on the xml nodes, but it transforms properly.

like image 100
Jeremy Holovacs Avatar answered Jan 22 '23 17:01

Jeremy Holovacs