问题
I need to remove elements from an existing config file on uninstall. Here is the relevant Wix:
<Component Id="Dynamics.exe.config" DiskId="1" Permanent="yes">
<File Id="AppConfig" Name="Dynamics.exe.config" Source="$(var.ProgramFilesDir)\Microsoft Dynamics\GP2010\Dynamics.exe.config" KeyPath="yes" />
<util:XmlConfig
Id="AppSettings"
Action="create"
ElementPath="//configuration"
Name="appSettings"
File="[#AppConfig]"
Sequence="1"
VerifyPath="appSettings"
Node="element"
On="install"/>
<util:XmlConfig
Id="AppSettings1"
Action="create"
ElementPath="//configuration/appSettings"
Name="add"
File="[#AppConfig]"
Sequence="2"
VerifyPath="add[\[]@key='AppName'[\]]"
Node="element"
On="install"/>
<util:XmlConfig
Id="AppSettingsKey1"
ElementPath="AppSettings1"
Name="key"
Value="AppName"
File="[#AppConfig]"
Sequence="3" />
<util:XmlConfig
Id="AppSettingsValue1"
ElementPath="AppSettings1"
Name="value"
Value="MyApp"
File="[#AppConfig]"
Sequence="4" />
<util:XmlConfig
Id="AppSettingsRemove1"
Action="delete"
ElementPath="//configuration/appSettings"
File="[#AppConfig]"
Sequence="2"
VerifyPath="add[\[]@key='AppName'[\]]"
Node="element"
On="uninstall"/>
The create Actions run. However, the delete/uninstall Action does not run. It does not modify the file. It seems like the file is being skipped over during an uninstall.
回答1:
You have configure the component Permanent attribute as Yes. That way the change will be kept during uninstall.
Try set as false.
I have test the following code, and it meets your requirements.
You can find full test code here
<Fragment>
<ComponentGroup Id="ProductComponents"
Directory="INSTALLFOLDER">
<Component Id="CMP_ConfigFile"
Guid="{24D22D04-1A98-40D1-83EC-87E68A87A07C}"
Permanent="yes"
KeyPath="yes"
NeverOverwrite="yes">
<File Id="ConfigFile"
src="administration.config"></File>
</Component>
<Component Id="CMP_XMLConfigInstallChange"
Guid="{B1B3B46A-0606-44F4-AEB6-58C5019F5C82}"
KeyPath="yes">
<util:XmlConfig Id="Add_ElementTest"
File="[#ConfigFile]"
ElementPath="/configuration/configSections"
Action="create"
Name="section"
Node="element"
On="install"
Sequence="5000">
<util:XmlConfig Id="Name_Test"
File="[#ConfigFile]"
ElementId="Add_ElementTest"
Name="name"
Value="TEST"></util:XmlConfig>
</util:XmlConfig>
</Component>
<Component Id="CMP_XMLConfig_UninstallChange"
Guid="{E1A01B17-247E-4717-8DC0-A923A8E90BE4}"
KeyPath="yes">
<util:XmlConfig Id="Remove_ElementTest"
File="[#ConfigFile]"
ElementPath="/configuration/configSections"
VerifyPath="/configuration/configSections/section[\[]@name='TEST'[\]]"
Action="delete"
Node="element"
On="uninstall"
Sequence="5000">
</util:XmlConfig>
</Component>
</ComponentGroup>
来源:https://stackoverflow.com/questions/17573058/in-wix-why-can-i-not-get-xmlconfig-uninstall-delete-to-work