Wix卸载程序不会删除文件。

4
我有一个带WiX安装程序的C#项目。
当我安装我的应用程序时,一切正常。我有:
- 在Program Files (x86)中的公司文件夹,包含我的应用程序文件夹和驱动程序文件夹。 - 桌面上的快捷方式 - 开始菜单中的快捷方式
当应用程序被安装后,我可以运行我的msi并选择卸载选项。但是当我卸载我的应用程序时,只有驱动程序文件夹(MyApplication_Drivers)被删除。我的应用程序文件夹和快捷方式仍然存在。
我错过了什么?
以下是我的product.wxs代码(整个代码因为我不知道问题从哪里来):
<?xml version="1.0" encoding="UTF-8"?>
<?define compagny = "My compagny"?>
<?define product = "MyApplication"?>
<?define version = "!(bind.FileVersion.MyApplication.exe)"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="*"
           Name="$(var.product)"
           Language="1033"
           Version="$(var.version)"
           Manufacturer="$(var.compagny)"
           UpgradeCode="***">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    <Media Id="1" Cabinet="MyApplication.cab" EmbedCab="yes"/>

    <Feature Id="ProductFeature" Title="$(var.product)" Level="1">
      <ComponentGroupRef Id="ProductComponents"/>
      <ComponentRef Id ="InstallFonts" />
      <ComponentRef Id ="ApplicationShortcut"/>
      <ComponentRef Id ="ApplicationShortcutDesk"/>
    </Feature>

    <Property Id="WIXUI_INSTALLDIR" Value="COMPAGNYFOLDER"/>    

    <WixVariable Id="WixUIBannerBmp"
                 Value=".\Images\WixUIBannerBmp.bmp"/>
    <WixVariable Id="WixUIDialogBmp"
                 Value=".\Images\WixUIDialogBmp.bmp"/>

    <UI>
      <UIRef Id="WixUI_Custom"/>      

      <Publish Dialog="WelcomeDlg"
               Control="Next"
               Event="NewDialog"
               Value="InstallDirDlg"
               Order="2">1</Publish>

      <Publish Dialog="InstallDirDlg"
               Control="Back"
               Event="NewDialog"
               Value="WelcomeDlg"
               Order="2">1</Publish>
    </UI>
    </Product>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="FontsFolder" />

      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="$(var.compagny)"/>
      </Directory>

      <Directory Id="DesktopFolder" SourceName="Desktop"/>

      <Directory Id="ProgramFilesFolder">
        <Directory Id="COMPAGNYFOLDER" Name="$(var.compagny)">
          <Directory Id="INSTALLFOLDER" Name="$(var.product)">
            <Directory Id="fr" Name="fr"/>
            <Directory Id="SETTINGS" Name="Settings">
              <Directory Id="PRINTERS" Name="Printers"/>
            </Directory>
          </Directory>
          <Directory Id="Drivers" Name="MyApplication_Drivers"/>
        </Directory>
      </Directory>
    </Directory>
  </Fragment>

  <Fragment>
    <DirectoryRef Id="ApplicationProgramsFolder">
      <Component Id="ApplicationShortcut" Guid="***">
        <Shortcut Id="ApplicationStartMenuShortcut"
                  Name="$(var.product)"
                  Description="$(var.product) application"
                  Target="[#MyApplication.exe]"
                  WorkingDirectory="INSTALLFOLDER"/>
        <RemoveFolder Id="ApplicationProgramsFolder" On="uninstall"/>
        <RegistryValue Root="HKCU" Key="SOFTWARE\$(var.compagny)\$(var.product)" Name="installedStart" Type="integer" Value="1" KeyPath="yes"/>
      </Component>
    </DirectoryRef>

    <DirectoryRef Id="DesktopFolder">
      <Component Id="ApplicationShortcutDesk" Guid="***">
        <Shortcut Id="ApplicationStartDeskShortcut"
                  Name="$(var.product)"
                  Description="$(var.product) application"
                  Target="[#MyApplication.exe]"
                  WorkingDirectory="INSTALLFOLDER"/>
        <RemoveFolder Id="DesktopFolder" On="uninstall"/>
        <RegistryValue Root="HKCU" Key="SOFTWARE\$(var.compagny)\$(var.product)" Name="installedDesk" Type="integer" Value="1" KeyPath="yes"/>
      </Component>
    </DirectoryRef>

    <DirectoryRef Id="FontsFolder">
      <Component Id="InstallFonts" Guid="{***}" Permanent="yes">
        <File Id="OCRB_Medium.ttf" Source="$(var.SolutionDir)_Required\OCRB_Medium.ttf" TrueType="yes" />
        <File Id="OCRBS___.TTF" Source="$(var.SolutionDir)_Required\OCRBS___.TTF" TrueType="yes" />
      </Component>
    </DirectoryRef>
  </Fragment>

    <Fragment>
    <ComponentGroup Id="ProductComponents">
      <!-- Application -->
      <Component Id="ProductComponent" Guid="{***}" Directory="INSTALLFOLDER" UninstallWhenSuperseded="yes">
        <!-- DLL -->
        <File Id="Bitmap.Core.dll" Source="$(var._Delivery.TargetDir)..\bin\Bitmap.Core.dll"/>
        <File Id="PdfLib.dll" Source="$(var._Delivery.TargetDir)..\bin\PdfLib.dll"/>

        <!-- EXE -->
        <File Id="MyApplication.exe" Source="$(var._Delivery.TargetDir)..\bin\MyApplication.exe"/>
        <File Id="MyApplication.exe.config" Source="$(var._Delivery.TargetDir)..\bin\MyApplication.exe.config"/>
      </Component>

      <!-- fr -->
      <Component Id="FRComponent" Guid="{***}" Directory="fr" UninstallWhenSuperseded="yes">
        <File Id="resources-fr.dll" Source="$(var._Delivery.TargetDir)..\bin\fr\resources-fr.dll" />
      </Component>

      <!-- Settings -->
      <Component Id="SetComponent" Guid="{***}" Directory="SETTINGS" UninstallWhenSuperseded="yes">
        <File Id="Settings.xml" Source="$(var.MyApplication.ProjectDir)Settings\Settings.xml" />
      </Component>

      <!-- Printers -->
      <Component Id="PrintComponent" Guid="{***}" Directory="PRINTERS" UninstallWhenSuperseded="yes">
        <File Id="Sticker.xml" Source="$(var.MyApplication.ProjectDir)Settings\Printers\Sticker.xml" />
      </Component>

      <!-- Resources -->
      <Component Id="Drivers" Guid="{***}" Directory="Drivers" UninstallWhenSuperseded="yes">
        <File Id="drivers.exe" Source="$(var.SolutionDir)_Required\drivers.exe"/>
        <File Id="user_manual_E.pdf" Source="$(var.SolutionDir)_Required\user_manual_E.pdf"/>
      </Component>
        </ComponentGroup>
    </Fragment>
</Wix>

编辑:

  • 旧版本代码完美运行

  • 我在卸载时打印了日志,这行似乎与此问题有关:

MSI(c)(E8:BC)[10:58:16:769]: 禁止卸载组件:{我的一个GUID},因为存在另一个客户端

2个回答

3

WiX不会卸载它认为已经安装的组件,我想这就是在这种情况下的情况。为什么?

  • 可能是GUID的重复使用(确保它们都是唯一的)
  • 早期版本的此安装程序在某个时候将这些组件标记为永久性

然而,你的代码与我在这个问题上看到的类似问题的区别在于,你没有将任何File元素列为 component 的 KeyPath。因此,我认为默认情况下父目录成为 KeyPath。KeyPath 用于确定组件是否安装在计算机上。如果 KeyPath 设置为目录,并且该目录已经存在,则很可能在卸载时不会被删除,因为它已经安装过了。

作为最佳实践,请尝试在每个Component中只有一个File,并在 File 元素中设置 KeyPath="yes"

关于这个主题的类似问题:


我之前看过一些类似的话题,但是问题对我并没有起作用。经过一些研究,似乎我的问题非常简单(我会添加答案)。 - A.Pissicat

2

我终于找到了问题所在。我的安装是正常的,我已经在我的电脑上安装了应用程序。

最近,我修改了我的Drivers目录的名称(不是Id)。我重新安装了我的应用程序(没有删除旧的),安装是OK的。之后,问题出现了。

解决方案很简单:

  • 使用Windows菜单删除我的应用程序(已安装了2个应用程序)

现在安装/卸载功能完美运行。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接