2015-02-12 141 views
1

我有以下wix文件應該在安裝過程中調用自定義操作。自定義操作將創建程序所需的一些文件。由於Wix只會刪除安裝程序安裝的文件,因此Custom操作創建的文件將會剩餘。所以我正在使用Wix提供的RemoveFileWix RemoveFile和RemoveFolder用於刪除剩餘物

我有以下的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.configproductcode.txt。應用程序將創建output.log,output.1.log,...。但是在編譯過程中,我得到以下錯誤

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除去剩飯?我提到this但沒有幫助。

UPDATE

我已經加入了GUID在組件標籤固定的問題。現在,在上面的代碼中如添加RemoveFolder時:

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

我得到的問題Unresolved reference to symbol 'Directory:apps' in section 'Fragment:'。我該如何解決?

回答

2

您只能使用RemoveFolder元素來刪除空文件夾,這樣不會有太大的幫助。 如果您有一個CustomAction在您的應用程序目錄中創建文件,我建議您不要爲這些元素創建RemoveFile元素。通常情況下,您將在應用程序目錄中創建帶有一次性數據的子文件夾,並且必須爲添加到該目錄的每個文件創建刪除元素。懶惰的方式是使用RemoveFolderEx Element。如該頁所述,您必須使用Remember property pattern來完成此項工作。 以下是如何實施這兩種技術的示例:

<?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>