Wix安装程序不会覆盖以前版本的可执行文件

时间:2015-04-25 19:55:35

标签: wix windows-installer

我有一个非常简单的安装程序 - 将一个dll复制到Program Files子文件夹并使用regsvr32.exe注册它。效果很好,但是如果安装了旧版本的dll,“修复”不会覆盖现有的dll。 dll已签名,其版本(版本)编号始终递增(例如2.0.0.123 - > 2.0.0.124)。

查看之前的类似帖子,我添加了RemoveExistingProducts并将ProductId指定为“*”。卸载然后安装新版本工作正常,但我真的需要修复来更新现有的dll。

还有什么我需要做的吗?

谢谢!

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">

  <!--
When creating a new install for the next version, these fields must be modified
-->
  <?define ProductVersion = "2.0.00" ?>

  <?define ProductId64 = "*" ?>
  <?define ProductId32 = "*" ?>

  <?define PackageId   = "45F34788-66AC-441C-B666-707FFA7F1EE9" ?>


  <!-- Product name as you want it to appear in Add/Remove Programs-->
  <?if $(var.Platform) = x64 ?>
  <?define ProductName = "XYZ (64 bit)" ?>
  <?define Win64 = "yes" ?>
  <?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
  <?define ProductId = "$(var.ProductId64)" ?>
  <?define MainDllName = "XYZ64.dll" ?>
  <?define MainDllSource = "..\..\bin\Win64\Release\XYZ64.dll" ?>
  <?else ?>
  <?define ProductName = "XYZ (32 bit)" ?>
  <?define Win64 = "no" ?>
  <?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
  <?define ProductId = "$(var.ProductId32)" ?>
  <?define MainDllName = "XYZ.dll" ?>
  <?define MainDllSource = "..\..\bin\Win32\Release\XYZ.dll" ?>
  <?endif ?>


  <?define UpgradeCode = "{C3763742-7C1C-4AB7-A404-F030B7550E97}" ?>


  <Product Id="$(var.ProductId)" Name="$(var.ProductName)" Language="1033" Version="$(var.ProductVersion)" Manufacturer="Advanced Messaging Systems LLC" UpgradeCode="$(var.UpgradeCode)">

    <Package Id="$(var.PackageId)" InstallerVersion="200" Compressed="yes" Description="XYZ Installer package"  InstallPrivileges="elevated"/>

    <!-- No restore point  -->
    <Property Id="MSIFASTINSTALL" Value="3" />

   <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="$(var.PlatformProgramFilesFolder)">
        <Directory Id="INSTALLLOCATION" Name="XYZ">

          <Component Id="XYZDll" Guid="E2CBEE41-6C0E-4A84-95C1-7282747B4A3D">
            <File Id='MainDll' Name="$(var.MainDllName)" DiskId='1' Source="$(var.MainDllSource)" SelfRegCost="0" />

            <!-- TODO: Insert files, registry keys, and other resources here. -->
          </Component>

        </Directory>
      </Directory>
    </Directory>

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

    <!-- Note: Custom actions to install/uninstall the dll using regsvr32.exe -->
    <CustomAction Id="RegisterDll"
                      Directory="INSTALLLOCATION"
                      ExeCommand='regsvr32.exe /s "[INSTALLLOCATION]$(var.MainDllName)"'

                      Return="check">
    </CustomAction>
    <CustomAction Id="UnregisterDll"
                  Directory="INSTALLLOCATION"
                  ExeCommand='regsvr32.exe /s /u "[INSTALLLOCATION]$(var.MainDllName)"'>
    </CustomAction>


    <Feature Id="ProductFeature" Title="XYZ" Level="1">
      <ComponentRef Id="XYZDll" />
      <!-- Note: The following ComponentGroupRef is required to pull in generated authoring from project references. -->
      <ComponentGroupRef Id="Product.Generated" />
    </Feature>

    <InstallUISequence>
      <Custom Action="WixCloseApplications" Before="AppSearch"/>
    </InstallUISequence>

    <InstallExecuteSequence>

      <!-- Uninstall previous version before installing this one. -->
      <RemoveExistingProducts Before="InstallInitialize"/>


      <SelfRegModules/>
    </InstallExecuteSequence>

    <Icon Id="XYZ.ico" SourceFile="..\Graphics\XYZ.ico"/>
    <Property Id="ARPPRODUCTICON" Value="XYZ.ico" />

    <!-- UI -->
    <UIRef Id="WixUI_InstallDir"/>
    <UIRef Id="WixUI_ErrorProgressText" />

    <WixVariable Id="WixUILicenseRtf" Value="..\EULA\license.rtf" />
    <WixVariable Id="WixUIBannerBmp"  Value="..\Graphics\banner.jpg" />
    <WixVariable Id="WixUIDialogBmp"  Value="..\Graphics\logo.jpg" />


    <!-- End UI -->
  </Product>
</Wix>

更新即可。修改升级条目后,以下内容对我有用:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">

  <!--
When creating a new install for the next version, these fields must be modified
-->
  <?define ProductVersion = "2.0.4" ?>

  <?define ProductId64 = "*" ?>
  <?define ProductId32 = "*" ?>

  <?define PackageId   = "*" ?>


  <!-- Product name as you want it to appear in Add/Remove Programs-->
  <?if $(var.Platform) = x64 ?>
  <?define ProductName = "XYZ (64 bit)" ?>
  <?define Win64 = "yes" ?>
  <?define PlatformProgramFilesFolder = "ProgramFiles64Folder" ?>
  <?define ProductId = "$(var.ProductId64)" ?>
  <?define MainDllName = "XYZ64.dll" ?>
  <?define MainDllSource = "..\..\bin\Win64\Release\XYZ64.dll" ?>
  <?else ?>
  <?define ProductName = "XYZ (32 bit)" ?>
  <?define Win64 = "no" ?>
  <?define PlatformProgramFilesFolder = "ProgramFilesFolder" ?>
  <?define ProductId = "$(var.ProductId32)" ?>
  <?define MainDllName = "XYZ.dll" ?>
  <?define MainDllSource = "..\..\bin\Win32\Release\XYZ.dll" ?>
  <?endif ?>


  <?define UpgradeCode = "{C3763742-7C1C-4AB7-A404-F030B7550E97}" ?>


  <Product
    Id="$(var.ProductId)"
    Name="$(var.ProductName)"
    Language="1033"
    Version="$(var.ProductVersion)"
    Manufacturer="Advanced Messaging Systems LLC"
    UpgradeCode="$(var.UpgradeCode)"
    >

    <Package Id="$(var.PackageId)"
             InstallerVersion="200"
             Compressed="yes"
             Description="XYZ Installer package"
             InstallPrivileges="elevated"
     />

    <!-- No restore point  -->
    <Property Id="MSIFASTINSTALL" Value="3" />


    <Upgrade Id="$(var.UpgradeCode)">
      <UpgradeVersion Minimum="1.0.0"
                      IncludeMinimum="yes"
                      OnlyDetect="no"
                      Maximum="$(var.ProductVersion)"
                      IncludeMaximum="no"
                      Property="PREVIOUSFOUND" />
    </Upgrade>


    <Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="$(var.PlatformProgramFilesFolder)">
        <Directory Id="INSTALLLOCATION" Name="XYZ">

          <Component Id="XYZDll" Guid="E2CBEE41-6C0E-4A84-95C1-7282747B4A3D">
            <File Id='MainDll' Name="$(var.MainDllName)" DiskId='1' Source="$(var.MainDllSource)" SelfRegCost="0" />

            <!-- TODO: Insert files, registry keys, and other resources here. -->
          </Component>

        </Directory>
      </Directory>
    </Directory>

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

    <!-- Note: Custom actions to install/uninstall the dll using regsvr32.exe -->
    <CustomAction Id="RegisterDll"
                      Directory="INSTALLLOCATION"
                      ExeCommand='regsvr32.exe /s "[INSTALLLOCATION]$(var.MainDllName)"'

                      Return="check">
    </CustomAction>
    <CustomAction Id="UnregisterDll"
                  Directory="INSTALLLOCATION"
                  ExeCommand='regsvr32.exe /s /u "[INSTALLLOCATION]$(var.MainDllName)"'>
    </CustomAction>


    <Feature Id="ProductFeature" Title="XYZ" Level="1">
      <ComponentRef Id="XYZDll" />
      <!-- Note: The following ComponentGroupRef is required to pull in generated authoring from project references. -->
      <ComponentGroupRef Id="Product.Generated" />
    </Feature>

    <InstallUISequence>
      <Custom Action="WixCloseApplications" Before="AppSearch"/>
    </InstallUISequence>

    <InstallExecuteSequence>

     <RemoveExistingProducts After="InstallInitialize"/>

      <SelfRegModules/>

    </InstallExecuteSequence>

    <Icon Id="XYZ.ico" SourceFile="..\Graphics\XYZ.ico"/>
    <Property Id="ARPPRODUCTICON" Value="XYZ.ico" />

    <!-- UI -->
    <UIRef Id="WixUI_InstallDir"/>
    <UIRef Id="WixUI_ErrorProgressText" />

    <WixVariable Id="WixUILicenseRtf" Value="..\EULA\license.rtf" />
    <WixVariable Id="WixUIBannerBmp"  Value="..\Graphics\banner.jpg" />
    <WixVariable Id="WixUIDialogBmp"  Value="..\Graphics\logo.jpg" />


    <!-- End UI -->
  </Product>
</Wix>

3 个答案:

答案 0 :(得分:8)

如果你想要一个主要的升级,请从WiX MajorUpgrade元素开始。升级的一般规则是:

  1. 旧产品的不同ProductCode和PackageCode。
  2. 在前三个字段中的某处增加ProductVersion。
  3. 与旧产品相同的UpgradeCode。
  4. 执行某些操作(例如Wix MajorUprade或Upgrade元素)以确保您已进行升级。
  5. 每个用户安装不会升级每个系统安装,反之亦然。
  6. 在您的原始情况下,未遵循规则1和2意味着Windows认为已安装相同的产品并进入修复模式。这应该是你的第一个警告,因为重大升级看起来像是全新安装,而不是维修。如果您在“程序和功能”中有两个条目,则表示尚未满足这4个要求中的一个或多个。如果您收到“已安装此产品的另一个版本”,则表示您未遵循规则1,并且行为的变化与ProductCode和PackageCode值相比与已安装的产品相比较。

答案 1 :(得分:5)

我很惊讶这条线实际上是由 Wix 编译器链接器允许的:

 <?define PackageId   = "45F34788-66AC-441C-B666-707FFA7F1EE9" ?>

如果这确实有效并且经过了我尚未经过测试,则表示您的软件包具有硬编码软件包ID 。我认为Wix有针对此问题的保护措施?也许它呢?我们应该向Wix社区查看是否允许使用硬编码包guid。我想这可能是调试和测试的必要条件 - 但至少应该有一个编译器警告。

包GUID 的想法 是每个已编译的MSI文件都应该是唯一的。它只是在那里唯一地标识文件。 根据定义,Windows Installer将两个具有相同程序包guid的不同MSI文件视为同一文件。导致各种x文件问题。因此,包GUID应始终自动生成,因为它应该是唯一的。请首先尝试解决此问题,以检查这是否解决了您的整体问题。设置等于*。

我的建议是自动生成 包ID 产品ID ,但要设置硬编码升级代码。升级代码标识&#34; 系列产品&#34;并且无论语言和版本如何,都可用于识别产品的任何实例。为64位和32位设置使用单独的升级代码可能很有用,因为两个版本可以在某些系统上同时安装。

您可能还想取消使用regsvr32.exe 进行自我注册,并从您的dll中提取COM数据以获得正确的MSI支持: MSI register dll - Self-Registration considered harmful 。也许还要检查一下: Register ActiveX exe server using WiX (如果Heat没有工作,请查看RegSpy2。)

另请注意you can leave out a lot of source attributes from your Wix xml file并依赖于Wix默认值而不是硬编码值。

有关GUID和文件替换的更多详细信息:

答案 2 :(得分:2)

简短回答(另一个变得过于混乱):尝试删除此行并通过将其设置为“*”来自动生成包ID:

 <?define PackageId   = "45F34788-66AC-441C-B666-707FFA7F1EE9" ?>

请注意,在卸载所有MSI版本之后,必须停止使用它们。这是由于错误的硬编码包guid导致不可预测和无法预料的问题。