首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >卸载时Wix删除appdata文件夹

卸载时Wix删除appdata文件夹
EN

Stack Overflow用户
提问于 2016-05-13 14:40:14
回答 1查看 3K关注 0票数 2

我正在使用WiX3.11,并尝试了许多不同的方法和方法,似乎无法理解为什么Wix不删除我的ApplicationDataFolder文件夹。在安装期间,我在ApplicationDataFolder位置为用户创建文件夹。

我的应用程序使用日志记录,并将其与目录中的其他一些内容一起存储。在卸载过程中,应用程序文件夹中的所有内容都将被删除,但是带有日志和其他文件的appdata文件夹将保持不变。

我不知道为什么或者我错过了什么。

WXS模板

代码语言:javascript
复制
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
  <Product Id="*" UpgradeCode="9e578e3d-0119-425c-8633-f54ffaaa4929" Name="@product.name@" Version="@product.version@" Manufacturer="@product.company@" Language="1033">
    <Package InstallerVersion="400" Compressed="yes" InstallScope="perMachine" Comments="@product.version@" Description="@product.description@"/>
    <Media Id="1" Cabinet="SomeApp.cab" EmbedCab="yes" />

    <!-- Installer Properties -->
    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
    <PropertyRef Id="WIX_IS_NETFRAMEWORK_46_OR_LATER_INSTALLED"/>

    <!-- Installer Resources -->
    <Icon Id="ApplicationIcon" SourceFile="SomeApp 4\SomeApp 4_vista.ico"/>
    <Property Id="ARPPRODUCTICON" Value="ApplicationIcon" />

    <Property Id="INSTALLDIR">
        <RegistrySearch Key="SOFTWARE\Acme\SomeApp" 
                        Root="HKCU" Type="raw" 
                        Id="APPLICATIONFOLDER_REGSEARCH" Name="installation-path" />
    </Property>

    <WixVariable Id="WixUILicenseRtf" Value="SomeApp 4\license.rtf" />
    <WixVariable Id="WixUIBannerBmp" Value="WixUIBannerBmp.bmp" />
    <WixVariable Id="WixUIDialogBmp" Value="WixUIDialogBmp.bmp" />

    <!-- Check Existing Install -->
    <Upgrade Id="9e578e3d-0119-425c-8633-f54ffaaa4929">
        <UpgradeVersion Minimum="@product.version@" OnlyDetect="yes" Property="NEWERVERSIONDETECTED"/>
        <UpgradeVersion Minimum="0.0.0" Maximum="@product.version@" IncludeMinimum="yes" IncludeMaximum="no" Property="OLDERVERSIONBEINGUPGRADED"/>   
    </Upgrade>
    <Condition Message="A newer version of this software is already installed.">NOT NEWERVERSIONDETECTED</Condition>

    <!-- Prerequisites -->
    <Condition Message="This application requires .NET Framework 4.6 or newer. Please install the .NET Framework then run this installer again.">
      <![CDATA[Installed OR WIX_IS_NETFRAMEWORK_46_OR_LATER_INSTALLED]]>
    </Condition>

    <Condition Message="This application requires at least Windows 7 or Windows Server 2008 R2. Please upgrade your computer to a supported operating system and run this installer again.">
      <![CDATA[Installed OR (VersionNT >= 601)]]>
    </Condition>

    <!-- Define the directory structure -->
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder" Name="ProgramFiles">
        <Directory Id="INSTALLDIR" Name="@product.company@">
            @product.applicationfiles@
            @product.servicefiles@
        </Directory>
      </Directory>
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="@product.name@"/>
        <Directory Id="ServiceProgramsFolder" Name="@product.name@"/>
      </Directory>
      <Directory Id="DesktopFolder" Name="Desktop" /> 
      <Directory Id="LocalAppDataFolder">
        <Directory Id="ApplicationDataFolder" Name="Acme" />
      </Directory>            
    </Directory>

    <DirectoryRef Id="ApplicationProgramsFolder">
        <Component Id="ApplicationShortcut" Guid="1e578e4d-0229-425c-8633-f54ffaaa4901">
            <Shortcut Id="ApplicationStartMenuShortcut" 
                Name="SomeApp 4.6" 
                Description="@product.company@ @product.name@ @product.version@"
                Target="[INSTALLDIR]SomeApp 4\SomeApp.UserInterface.exe"
                WorkingDirectory="INSTALLDIR"
                Icon ="ApplicationIcon"/>       
            <Shortcut Id="ApplicationStartMenuShortcut2" 
                Name="SomeApp 4.6 (Multiple Instances)" 
                Description="@product.company@ @product.name@ @product.version@"
                Target="[INSTALLDIR]SomeApp 4\SomeApp.UserInterface.exe"
                Arguments="MultipleInstance=True"
                WorkingDirectory="INSTALLDIR"
                Icon ="ApplicationIcon"/>  
            <Shortcut Id="ApplicationStartMenuShortcut3" 
                Name="SomeApp 4.6 (Notifications)" 
                Description="@product.company@ @product.name@ @product.version@"
                Target="[INSTALLDIR]SomeApp 4\SomeApp.UserInterface.exe"
                Arguments="Notifications=True"
                WorkingDirectory="INSTALLDIR"
                Icon ="ApplicationIcon"/>                   
            <Shortcut Id="HelpStartMenuShortcut" 
                Name="SomeApp 4.6 Help" 
                Target="[INSTALLDIR]SomeApp 4\Documentation\SomeApp.chm"
                WorkingDirectory="INSTALLDIR"/>                 
            <Shortcut Id="UninstallProduct"             
                      Name="Uninstall SomeApp 4.6"
                      Target="[SystemFolder]msiexec.exe"
                      Arguments="/x [ProductCode]"
                      Description="Uninstall @product" />                    
            <Shortcut Id="desktopshortcut" 
                      Directory="DesktopFolder" 
                      Name="SomeApp 4.6" 
                      WorkingDirectory="INSTALLDIR" 
                      Target="[INSTALLDIR]SomeApp 4\SomeApp.UserInterface.exe" />
            <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
            <util:RemoveFolderEx On="uninstall" Property="ApplicationDataFolder" />                       
       </Component>
    </DirectoryRef>

    <DirectoryRef Id="ServiceProgramsFolder">
       <Component Id="ServiceShortcut" Guid="9e578e3d-0229-425c-8633-f54ffaaa4901">
            <Shortcut Id="ServiceStartMenuShortcut"
                Name="@product.name@ Reporting Service" 
                Description="@product.name@ Reporting Service"
                Target="[INSTALLDIR]Reporting\SomeApp.ReportingService.exe"
                WorkingDirectory="INSTALLDIR"
                Icon ="ApplicationIcon"/>
            <RemoveFolder Id="ServiceProgramsFolder" On="uninstall"/>                    
            <RegistryValue Root="HKCU" Key="Software\Microsoft\Acme\SomeApp" Name="service-installed" Type="integer" Value="1" KeyPath="yes"/>                   
       </Component>
    </DirectoryRef>   

    <DirectoryRef Id="INSTALLDIR">
        <Component Id="CleanupMainApplicationFolder" Guid="*">
            <RegistryValue Root="HKCU" Key="SOFTWARE\Acme\SomeApp" Name="installation-path" Type="string" Value="[INSTALLDIR]" KeyPath="yes" />
            <util:RemoveFolderEx On="uninstall" Property="INSTALLDIR" />                
            <util:RemoveFolderEx On="uninstall" Property="ApplicationDataFolder" />                
        </Component>
    </DirectoryRef>

    <!--  Feature: SomeApp Application -->            
    <Feature Id="Feature.Application"
                     Title="SomeApp 4 - Application"
                     Description="SomeApp is an asset management and maintenance application designed to optimize asset value and improve manufacturing productivity."
                     ConfigurableDirectory="INSTALLDIR"
                     Level="1"
                     AllowAdvertise="no">
                    @product.applicationcomponents@
                    <ComponentRef Id="ApplicationShortcut" />                    
                    <ComponentRef Id="CleanupMainApplicationFolder" />                    
    </Feature>

    <!--  Feature: Reporting Service -->
    <Feature Id="Feature.Service"
                     Title="SomeApp 4 - Reporting Service"
                     Description="This service generates and delivers reports that have been scheduled in the SomeApp Maintenance Management System."
                     ConfigurableDirectory="INSTALLDIR"
                     Level="3"
                     AllowAdvertise="no">
                    @product.servicecomponents@    
                    <ComponentRef Id="ServiceShortcut" />                    
        <Component Id="ReportingServiceInstaller" Guid="B72CAA3F-F2DB-48D2-90DD-061209AB2CE5" Directory="INSTALLDIR">
            <CreateFolder />
            <File Id="ReportingService.exe" Name="ReportingService.exe" KeyPath="yes" Source="@product.sourcedir@\Reporting\SomeApp.ReportingService.exe"/>
            <ServiceInstall Id="ReportingServiceInstaller"
                Type="ownProcess"
                Vital="yes"
                Name="SomeApp Reporting Service"                    
                DisplayName="SomeApp - Reporting Service"
                Description="This service generates and delivers reports that have been scheduled in the SomeApp Maintenance Management System."
                Start="auto"
                Account="NT AUTHORITY\LocalService"
                ErrorControl="ignore"
                Interactive="no" />
        </Component>     

    </Feature>

    <CustomAction Id="Cleanup_logfile" Directory="INSTALLDIR" 
    ExeCommand="cmd /C &quot;rmdir %LOCALAPPDATA%\Acme /s /q&quot;" 
    Execute="deferred" Return="ignore" HideTarget="no" Impersonate="no" />

    <InstallExecuteSequence>
      <Custom Action="Cleanup_logfile" After="RemoveFiles" >
        REMOVE="ALL" 
      </Custom>
    </InstallExecuteSequence>

    <InstallExecuteSequence>
        <RemoveExistingProducts After="InstallValidate"/>
    </InstallExecuteSequence>   

    <UIRef Id="WixUI_FeatureTree" />
    <UI>
      <DialogRef Id="FilesInUse" />
      <DialogRef Id="MsiRMFilesInUse" />
      <!-- Add the GUI logic for installation -->
    </UI>
  </Product>
</Wix>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-05-13 14:59:14

我有一个使用util的项目:RemoveFolderEx,它正在正常工作。我唯一能看到的区别是,我在运行时显式地将属性设置为安装目录的值。我猜"INSTALLDIR“和"ApplicationDataFolder”实际上不是属性,因为它们存储在msi的目录表中,而不是属性表中。(使用ORCA检查)

试着做

代码语言:javascript
复制
<SetProperty Id='AcmeAppDataFolderToRemove' Value='[ApplicationDataFolder]' After='AppSearch'/>

然后将util:RemoveFolderEx改为

代码语言:javascript
复制
<util:RemoveFolderEx On="uninstall" Property="AcmeAppDataFolderToRemove" />

看看能不能行。(您可能需要使用Value='ApplicationDataFolder‘,而不需要使用[]的不确定性。)

作为对您的编辑的响应,我查看了RemoveFolderEx页面,这看起来很重要

实现RemoveFolderEx的自定义操作是通过为指定的根文件夹的每个子文件夹向RemoveFile表写入临时行来实现的。因为这可能会极大地影响Windows的文件成本,所以临时行必须在CostInitialize标准操作之前写入。不幸的是,MSI直到稍后在CostFinalize操作中才为包中的目录层次结构创建属性。

我认为将其设置为目录可以工作,但很明显,当RemoveFolderEx操作实际执行时,这些目录还没有值。因此,当尝试解析属性或设置属性时,它们实际上只是空的。

我说我的安装程序所做的和它实际做的事情的不同之处在于,我通过一个RegistrySearch获得了我将属性设置为的值。

代码语言:javascript
复制
<Property Id="INSTALLDIR">
    <RegistrySearch 
        Id='InstallDirRegistrySearch' 
        Type='raw'
        Root='HKLM' 
        Key='SOFTWARE\$(var.OEMRegistryRootKeyName)' 
        Name='SDKPath' />
</Property>
<SetProperty Id='SDKFolderToRemove' Value='[INSTALLDIR]\$(var.OEMProduct) SDK' After='AppSearch'/>

因此,我会尝试将appdata dir写入注册表项,并通过注册表搜索将值输入属性,然后在远程访问中使用该属性,您可能不需要setproperty,我只是使用它,因为我需要INSTALLDIR下的一个文件夹,但在您的示例中,您可以让注册表键成为正确的文件夹。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37212919

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档