Wix RemoveFile和RemoveFolder用于删除残留物 [英] Wix RemoveFile and RemoveFolder for removing leftovers

查看:51
本文介绍了Wix RemoveFile和RemoveFolder用于删除残留物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下wix文件,该文件应在安装过程中调用自定义操作.自定义操作将创建程序所需的一些文件.由于Wix仅会删除安装程序安装的那些文件,因此将保留自定义"操作创建的文件.因此,我求助于Wix提供的 RemoveFile .

I have following wix file that is supposed to call the Custom Action during the installation. The custom action will create some files required for program. As Wix will only remove only those files that were installed by installer, files created by Custom action will be leftover. So I am resorting to RemoveFile provided by Wix.

我有以下Wix文件.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="*" Name="WixCustomAction" Language="1033" Version="1.0.0.0" Manufacturer="Sarvagya" UpgradeCode="1d77ebdc-2ba2-4b34-b013-7c8a8adcef5b">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <MediaTemplate EmbedCab="yes"/>

    <Feature Id="ProductFeature" Title="WixCustomAction" Level="1">
        <ComponentGroupRef Id="ProductComponents" />
  <!--<ComponentGroupRef Id="RemoveLeftOvers" />-->
</Feature>
</Product>

<Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
        <Directory Id="WindowsVolume">
            <Directory Id="INSTALLFOLDER" Name="LearningWix" />
        </Directory>
    </Directory>
</Fragment>

<Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
  <Component Id="SomeDLL">
    <File Source="C:\boost_1_55_0_dyn\stage\lib\boost_atomic-vc100-mt-1_55.dll" />
  </Component>
  <Component Id="RemovingFiles">
    <RemoveFile Id="ConfigRemove" Name="lpa.config" On="uninstall"/>
    <RemoveFile Id="LogsRemove" Name="*.log" On="uninstall"/>
    <RemoveFile Id="ProductCodeRemove" Name="productcode.txt" On="uninstall"/>
  </Component>
    </ComponentGroup>    
<Binary Id="SetupCA"  SourceFile="..\LearnCustomAction\bin\Release\LearnCustomAction.CA.dll"/>
<CustomAction Id="FileWrite" Execute="immediate" BinaryKey="SetupCA" DllEntry="WriteFileToDisk" />
<InstallExecuteSequence>
  <Custom Action="FileWrite" Before="InstallFinalize"></Custom>
</InstallExecuteSequence>
</Fragment>

自定义操作"将创建文件 lpa.config productcode.txt .应用程序将创建 output.log,output.1.log,... .但是在编译过程中,出现以下错误

The Custom Action will create files lpa.config and productcode.txt . Apps will create output.log, output.1.log, ... . But during compilation, I get following error

The Component/@Guid attribute's value '*' is not valid for this component because it does not meet the criteria for having an automatically generated guid. Components using a Directory as a KeyPath or containing ODBCDataSource child elements cannot use an automatically generated guid. Make sure your component doesn't have a Directory as the KeyPath and move any ODBCDataSource child elements to components with explicit component guids.

我应该如何正确使用 RemoveFile 来删除剩菜剩饭?我提到了,但没有帮助.

How am I supposed to correctly use RemoveFile for removing the leftovers? I referred to this but no help.

更新

我通过在Component标签中添加GUID来解决此问题.现在,当在上述代码中添加 RemoveFolder 时,例如:

I have fixed the issue by adding a GUID in Component tag. Now when Adding RemoveFolder in above code eg:

    <RemoveFolder Id="LeftOverAppsRemove" On="uninstall" Directory="apps"/>
    <RemoveFolder Id="LeftOverTempRemove" On="uninstall" Directory="temp"/>

我收到问题片段:"部分中对符号"Directory:apps"的引用未解决.我该如何解决?

I get issue Unresolved reference to symbol 'Directory:apps' in section 'Fragment:'. How do I fix this?

推荐答案

您只能使用 RemoveFolder 元素删除空文件夹,因此不会有太大帮助.如果您有一个CustomAction在应用程序目录中创建文件,则建议您不要为这些文件创建 RemoveFile 元素.通常,您将在应用程序目录中创建具有一次性数据的子文件夹,并且必须为添加到目录中的每个文件创建删除元素.懒惰的方法是利用 RemoveFolderEx元素.如该页面上所述,您必须使用

You can only use the RemoveFolder element to remove empty folders, so that won't help much. If you have a CustomAction that creates files in your application directory, I suggest you don't create RemoveFile elements for those. Oftentimes, you're going to create subfolders with disposable data in your application directory and you'd have to create removal elements for every file that is added to the directory. The lazy way to go about this is to make use of the RemoveFolderEx Element. As described on that page, you have to use the Remember property pattern to make this work. Here is an example how to implement these two techniques:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
  <Fragment>
    <ComponentGroup Id="CommonFiles" Directory="INSTALLFOLDER">
        <Component Id="SomeDLL" Guid="PUT-GUID-HERE">
          <File Source="C:\boost_1_55_0_dyn\stage\lib\boost_atomic-vc100-mt-1_55.dll" />
          <util:RemoveFolderEx Id="RemoveAdditionalFiles" On="uninstall" Property="REMOVAL"/>
        </Component>
        <Component>
          <RegistryValue Root="HKCU" Key="SOFTWARE\YOURCOMPANY\YOURPRODUCT" Name="CompleteRemoval" Value="[INSTALLFOLDER]" Type="string"/>
          <RemoveFolder Id="Cleanup" On="uninstall"/>
        </Component>
    </ComponentGroup>
    <Property Id="REMOVAL">
      <RegistrySearch Id="RemovalProperty" Root="HKCU" Key="SOFTWARE\YOURCOMPANY\YOURPRODUCT" Name="CompleteRemoval" Type="raw" />
    </Property>
    <CustomAction Id='SaveCmdLineValue' Property='REMOVAL_CMD'
      Value='[REMOVAL]' Execute='firstSequence' />
    <CustomAction Id='SetFromCmdLineValue' Property='REMOVAL'
      Value='[REMOVAL_CMD]' Execute='firstSequence' />
    <InstallUISequence>
      <Custom Action='SaveCmdLineValue' Before='AppSearch' />
      <Custom Action='SetFromCmdLineValue' After='AppSearch'>REMOVAL_CMD</Custom>
    </InstallUISequence>
    <InstallExecuteSequence>
      <Custom Action='SaveCmdLineValue' Before='AppSearch' />
      <Custom Action='SetFromCmdLineValue' After='AppSearch'>REMOVAL_CMD</Custom>
    </InstallExecuteSequence>
  </Fragment>
</Wix>

这篇关于Wix RemoveFile和RemoveFolder用于删除残留物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆