WIX - How to use RemoveFiles

余生颓废 提交于 2019-12-10 18:57:51

问题


We have multiple configuration files. Based on the environment selected, right file gets copied and the rest of the files should get deleted.
I am using RemoveFile but that doesn't delete anything or may be I am not using it right. Can someone give an example to delete *.config from [INSTALLDIR] during the install, after all files have been copied.


回答1:


In the example below RemoveFile is used to delete all icons (.lnk extension) on uninstallation, also the parent folder will be removed by using RemoveFolder

<DirectoryRef Id="DirName">
  <Component Id="cmpName" Guid="{429BC364-BE5F-4EC8-9AB9-8A522F8EC089}">
    <RemoveFile Id="removeDesktopShortcuts" On ="uninstall" Name="*.lnk"/>
    <RemoveFolder Id="RemoveFolder1" On="uninstall"/>
  </Component>
</DirectoryRef>



回答2:


Why don't you go with option of custom action. Create a method in C# or other and then call it after 'InstallFinalize'.

Example :

[CustomAction]
public static ActionResult RemoveConfigs(Session session)
{ 
    string configfiles = "\"" + session["INSTALLDIR"].ToString() + "*.config\"" ;
    System.Diagnostics.Process.Start("cmd.exe", "/C del " + configfiles);

    return ActionResult.Success;
}

In CustomAction.wxs add

<Custom Action="ZA_RemoveConfigs" After="InstallFinalize">NOT INSTALLED AND NOT REMOVE</Custom>


来源:https://stackoverflow.com/questions/7176188/wix-how-to-use-removefiles

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!