使用slowCheetah转换用户设置

本文关键字:设置 用户 转换 slowCheetah 使用 | 更新日期: 2023-09-27 17:53:30

我正在尝试根据构建配置文件更改我的默认用户配置,但是我无法找到正确的方法来使用它

<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="MyApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <userSettings>
        <MyApp.Properties.Settings>
            <setting name="Url" serializeAs="String">
                <value>
                    something
                </value>
            </setting>
        </MyApp.Properties.Settings>
    </userSettings>
</configuration>

I have been try

<!-- &amp it's an & escaped in xml-->
<add key="MyApp.Properties.Settings.Url" value="www.google.com" xdt:Transform="Replace" xdt:Locator="Match(key)"/>

但是它不工作。

我该怎么做?

使用slowCheetah转换用户设置

如果我没弄错的话,你会看到:

<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="MyApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <userSettings>
        <MyApp.Properties.Settings>
            <setting name="Url" serializeAs="String">
                <value>
                    something
                </value>
            </setting>
        </MyApp.Properties.Settings>
    </userSettings>
</configuration>

你想把它转换成:

(用<value>www.google.com</value>代替<value>something</value>

)
<?xml version="1.0"?>
<configuration>
    <configSections>
        <sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
            <section name="MyApp.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
        </sectionGroup>
    </configSections>
    <userSettings>
        <MyApp.Properties.Settings>
            <setting name="Url" serializeAs="String">
                <value>
                    www.google.com
                </value>
            </setting>
        </MyApp.Properties.Settings>
    </userSettings>
</configuration>
要做到这一点,最简单的方法是在转换文件中包含以下文本:
<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <userSettings>
        <MyApp.Properties.Settings>
            <setting name="Url" serializeAs="String">
                <value xdt:Transform="Replace">
                    www.google.com
                </value>
            </setting>
        </MyApp.Properties.Settings>
    </userSettings>
</configuration>

它将(<value xdt:Transform="Replace">)您的<value></value>替换为您想要的文本。

或者如果您想选择要用name="Url"属性替换的部分:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
    <userSettings>
        <MyApp.Properties.Settings>
            <setting name="Url" serializeAs="String" xdt:Transform="Replace" xdt:Locator="Match(name)">
                <value>
                    www.google.com
                </value>
            </setting>
        </MyApp.Properties.Settings>
    </userSettings>
</configuration>

我们在这里做同样的操作(替换:xdt:Transform="Replace"),但我们通过匹配属性来达到要更改的值:xdt:Locator="Match(name)"