我们可以使用
RemoveFolderEx
递归删除文件夹。为此,我们需要将以下内容添加到我们的 Wix 根元素中:
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util"
借自这里
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:util="http://wixtoolset.org/schemas/v4/wxs/util">
<Fragment>
<!-- Retrieve the CONFIGFOLDER "remembered" on installation -->
<Property Id="CONFIGFOLDER_PROP" Secure="yes">
<RegistrySearch Id="APPLICATIONFOLDER_REGSEARCH"
Root="HKCU"
Key="SOFTWARE\$(var.Manufacturer)\$(var.ProductName)"
Type="raw"
Name="Path" />
</Property>
<Component Id="CleanupConfigurationFolder" Directory="CONFIGFOLDER">
<!--
RemoveFolderEx requires that we "remember" the path for uninstall.
Read the path value and set the CONFIGFOLDER property with the value.
-->
<RegistryValue Root="HKCU"
Key="SOFTWARE\$(var.Manufacturer)\$(var.ProductName)"
Name="Path"
Type="string"
Value="[CONFIGFOLDER]"
KeyPath="yes" />
<!-- We need to use CONFIGFOLDER variable here or RemoveFolderEx
will not remove on "uninstall". -->
<util:RemoveFolderEx On="uninstall" Property="INSTALLFOLDER_PROP" />
<!-- Here <RemoveFolder/> if needed -->
</Component>
</Fragment>
</Wix>
文件夹定义:
<!-- Appdata (User data) -->
<StandardDirectory Id="AppDataFolder">
<Directory Id="CONFIGFOLDER" Name="!(loc.Company)"/>
</StandardDirectory>
不幸的是
RemoveFolderEx
没有将文件夹添加到RemoveFile表中,我们可能会收到此错误:
目录 CONFIGFOLDER 在用户配置文件中,但未在 删除文件表。
因此,作为解决方法,我在其后添加了以下虚拟线(
RemoveFolderEx
)
<!-- Dummy action to track the CONFIGFOLDER in the RemoveFile table -->
<RemoveFolder Id='RemoveConfigurationFolder' Directory='CONFIGFOLDER' On='uninstall' />