我正在尝试使用slowCheetah根据构建配置文件更改我的默认用户配置,但是我无法找到正确的方法来使用它
<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>
我一直在尝试
<!-- & it's an & escaped in xml-->
<add key="MyApp.Properties.Settings.Url" value="www.google.com" xdt:Transform="Replace" xdt:Locator="Match(key)"/>
但它不起作用。
我该怎么做?
答案 0 :(得分:9)
如果我做对了,你有这个:
<?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>something</value>
替换为<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>
最简单的方法是在转换文件中包含以下文本:
<?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)"