Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transform user settings with slowCheetah

I am trying you change my default user configuration according to the build profile with slowCheetah, however I am not able to find the right way to use it

<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 trying

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

but it doesn't work.

How can I do this?

like image 567
Edmondo1984 Avatar asked Jan 14 '13 17:01

Edmondo1984


1 Answers

If I get it right, you have this:

<?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>

And you want to transform it to:

(replace <value>something</value> with <value>www.google.com</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>

The easiest way to do this is to have the following text in your transformation file:

<?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>

It replaces (<value xdt:Transform="Replace">) your <value></value> with the text you want.

Or if you want to select the section to replace with the name="Url" attribute:

<?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>

We do the same action here (replace: xdt:Transform="Replace") but we reach the value to change by matching an attribute: xdt:Locator="Match(name)"

like image 194
cheesemacfly Avatar answered Nov 07 '22 12:11

cheesemacfly