我想用Wix編輯XML文件。我正在使用與Wix 3.7捆綁在一起的WixUtilExtension。 xml文件是在Visual Studio 2010中爲C#應用程序創建的設置文件。在這個文件中,我使用了一個用於在數組中存儲多個字符串值的元素。這是不變的設置文件的內容:如何使用wix將多個元素添加到XML配置文件中?
<configuration>
<applicationSettings>
<AppName.Properties.Settings>
<setting name="StringArray" serializeAs="Xml">
<value>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
</ArrayOfString>
</value>
</setting>
</AppName.Properties.Settings>
</applicationSettings>
</configuration>
我想<string>
元素添加到<ArrayOfString>
元素在這個文件中。一種方法是使用wix/UtilExtension命名空間中的<XmlConfig>
元素。我已經加入該元素來保持這樣的配置文件中的分量:
<Component Id="ProductComponent" Guid="$(var.ConfigGuid)">
<File Source="SettingsFile.exe.config" KeyPath="yes" Id="FILE_config" />
<util:XmlConfig
Name="string"
Value="My value"
File="[INSTALLFOLDER]SettingsFile.exe.config"
Id="String1"
On="install"
Action="create"
Node="element"
ElementPath="/configuration/applicationSettings/AppName.Properties.Settings/setting[\[]@name='StringArray'[\]]/value/ArrayOfString"
Sequence="100"
/>
</Component>
這導致另外一個<string>
元件到<ArrayOfString>
元件。另一個<string>
元素添加到設置文件,另一個XMLConfig的元素已被添加到一個不同的ID屬性設置項目的<Component>
元素和序列更高的價值屬性是這樣的:
<util:XmlConfig
Name="string"
Value="My second value"
File="[INSTALLFOLDER]SettingsFile.exe.config"
Id="String2"
On="install"
Action="create"
Node="element"
ElementPath="/configuration/applicationSettings/AppName.Properties.Settings/setting[\[]@name='StringArray'[\]]/value/ArrayOfString"
Sequence="101"
/>
安裝後微星的,在設置文件中<ArrayOfString>
元素看起來是這樣的:
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<string>My value</string><string>My second value</string></ArrayOfString>
我發現,這是可能的<XmlConfig>
屬性的值屬性設置爲這樣的屬性值:
<Property Id="STRING1VALUE" Value="My value" />
<util:XmlConfig Value="[STRING1VALUE]" ... />
這很好。我希望用戶能夠動態地在安裝過程中添加多個值,以便將可變數量的<string>
元素添加到設置文件中。 我的第一個方法是使用一個<?foreach?>
聲明是這樣的:
<?define values="My value;My second value"?>
<?foreach value in $(var.values)?>
<util:XmlConfig
Name="string"
Value="$(var.value)"
File="[INSTALLFOLDER]SettingsFile.exe.config"
Id="String$(var.value)"
On="install"
Action="create"
Node="element"
ElementPath="/configuration/applicationSettings/AppName.Properties.Settings/setting[\[]@name='StringArray'[\]]/value/ArrayOfString"
Sequence="101"
/>
<?endforeach?>
有這種方法的幾個問題:
- foreach語句使用不能設置值的預處理器變量屬性。
- Sequence屬性的值保持不變。
我想用戶存儲的值,其中由分號分隔值的屬性字符串元素,然後分析它們在foreach語句是這樣的:
<Property Id="VALUES" Value="My value;My second value" />
<?foreach value in [VALUES]?>
<util:XmlConfig
Name="string"
Value="$(var.value)"
File="[INSTALLFOLDER]SettingsFile.exe.config"
Id="String$(var.value)"
On="install"
Action="create"
Node="element"
ElementPath="/configuration/applicationSettings/AppName.Properties.Settings/setting[\[]@name='StringArray'[\]]/value/ArrayOfString"
Sequence="101"
/>
<?endforeach?>
這引發以下錯誤:
The util:XmlConfig/@Id attribute's value, 'String[VALUES]', is not a legal identifier.
Identifiers may contain ASCII characters A-Z, a-z, digits, underscores (_), or periods (.).
Every identifier must begin with either a letter or an underscore.
有沒有什麼辦法可以用XmlFile或XmlConfig元素創建可變數量的元素?是CustomAction這個問題的唯一解決方案嗎?