WiX XML 始终修改我的 .config 中的第一个元素,忽略关键属性

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

我试图理解 Wix,但我无法正确修改我的

.config
文件。这是一个例子:

<configuration>
 <configSections>
<!--All custom Sections must be delcared here-->
   <section name="settings" type="System.Configuration.AppSettingsSection"/>
 </configSections>
   <settings>
    <add key="DatabaseServer" value="localhost"/>
    <add key="DatabaseName" value="SampleDB"/>
  </settings>
</configuration>

我想在我的wix项目中修改

DatabaseName
,如下所示:

<Component Id="ModifyConfig" >
<File Id="AppConfigFile" Source="..path\to\my.config" KeyPath="yes" />
<util:XmlFile Id="SetAppSetting"
              File="[#AppConfigFile]"
              Action="setValue"
              ElementPath="/configuration/settings/add[key='DatabaseName']"
              Name="value"
              Value="somethingElse" />
</Component>

还尝试过

@key
。 但是,我只能修改第一个值(
DatabaseServer
)。我很确定这与关键属性没有得到正确解决有关,但 chatGPT 和快速的谷歌搜索显示我的方法与我已经在做的方法没有什么不同。

我该如何修改

DatabaseName

xml wix
1个回答
0
投票

您需要转义方括号(并使用

@key
):

<util:XmlFile
   ElementPath="/configuration/settings/add\[@key='DatabaseName'\]"
/>

[xxx]
的问题是这些片段在传递给 XmlFile 操作之前经过预处理(请参阅“格式化”)并由 MSI 替换。

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