C#apply app.config转换无法从父级别转换为子级别

问题描述 投票:0回答:1

我正在尝试在我的服务app.config中对子元素应用转换。我有几个服务,我只需要替换一个属性。

样品服务条目

<configuration>
     <cronService>
            <cronSettings>
                <services>
                    <service name="Name1" assembly="xxx.yyy.Applications.dll" interval="300" wakeUpTime="" onErrorEmail="[email protected]" continueAfterError="true" notifyEmailOnError="true" runOnStart="true" enable="true" />
    <service name="Name2" assembly="xxx.lll.Applications.dll" interval="300" wakeUpTime="" onErrorEmail="[email protected]" continueAfterError="true" notifyEmailOnError="true" runOnStart="true" enable="true" />
                </services>
            </cronSettings>
        </cronService>
</configuration>

在转换文件中,我尝试在父级别应用xdt:Transform并期望子级发生更改

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <cronService>
        <cronSettings emailSender="{AppTierCloudService}@zzz.com" xdt:Transform="SetAttributes" >
        <services xdt:Transform="SetAttributes" >
            <service onErrorEmail="[email protected], [email protected]"/>
        </services>
        </cronSettings>
    </cronService>
</configuration>

提到这个https://msdn.microsoft.com/en-us/library/dd465326.aspx

但这种转变并没有发生。有帮助吗?

c# asp.net .net asp.net-core console-application
1个回答
1
投票

在孩子的作品中添加xdt:Transform="SetAttributes"

<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <cronService>
        <cronSettings emailSender="{AppTierCloudService}@zzz.com" xdt:Transform="SetAttributes">
            <services>
                <service onErrorEmail="[email protected], [email protected]" xdt:Transform="SetAttributes" />
            </services>
        </cronSettings>
    </cronService>
</configuration>

转换后,XML看起来像这样:

<configuration>
    <cronService>
        <cronSettings emailSender="{AppTierCloudService}@zzz.com">
            <services>
                <service name="Name1" assembly="xxx.yyy.Applications.dll" interval="300" wakeUpTime="" onErrorEmail="[email protected], [email protected]" continueAfterError="true" notifyEmailOnError="true" runOnStart="true" enable="true" />
                <service name="Name2" assembly="xxx.lll.Applications.dll" interval="300" wakeUpTime="" onErrorEmail="[email protected], [email protected]" continueAfterError="true" notifyEmailOnError="true" runOnStart="true" enable="true" />
            </services>
        </cronSettings>
    </cronService>
</configuration>

特别感谢@Kirk Larkin展示了这个即时变换检查工具:https://webconfigtransformationtester.apphb.com

© www.soinside.com 2019 - 2024. All rights reserved.