web.config文件转换成在交替的命名空间 [英] web.config transforms in alternate namespaces

查看:222
本文介绍了web.config文件转换成在交替的命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web配置(截断显示重要的位),像这样:

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>

现在,我的web.config文件的所有部分适当改造后,除了这两个部分发布。我的直觉是这事做了某种XML命名空间的冲突,但它可能是别的东西完全,我猜。

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.

为什么不将这些部分变换?他们被完全忽略,并在发布的web.config文件完全不变的结束了。

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

推荐答案

原来答案是很简单:刚刚从两个节点删除默认的命名空间声明

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

在这种方式下,你失去了漂亮的智能感知的XML节点上,但它把正确

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

这篇关于web.config文件转换成在交替的命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆