4

我遵循了官方的主要升级指南,但我似乎遗漏了一些东西。这是我的MCVE

<?xml version="1.0" encoding="UTF-8"?>

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

  <Product Id="*" Codepage="1252" Language="1033" Manufacturer="Bla Corporation"
           Name="Bla" UpgradeCode="PUT-GUID-HERE" Version="31.00.0000">

    <Package Comments="Contact: Refael Sheinker, refael.sheinker@bla.com." Description="Bla"
             InstallerVersion="500"
             Compressed="yes"
             InstallScope="perMachine"
             Keywords="Installer,MSI,Database" Languages="1033" Manufacturer="Bla Corporation" Platform="x64" />

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

    <MajorUpgrade AllowDowngrades="no"
                  AllowSameVersionUpgrades="no"
                  Disallow="no"
                  IgnoreRemoveFailure="no"
                  MigrateFeatures="yes"
                  Schedule="afterInstallInitialize"
                  DowngradeErrorMessage="A later version of [ProductName] is already installed" />

    <Property Id="WIXUI_INSTALLDIR" Value="APPLICATIONROOTDIRECTORY" />
    <UIRef Id="WixUI_InstallDir" />

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFiles64Folder">
        <Directory Id="PROGRAMFILESSUBDIR" Name="Bla">
          <Directory Id="APPLICATIONROOTDIRECTORY" Name="BlaInternal" />
        </Directory>
      </Directory>
    </Directory>

    <DirectoryRef Id="APPLICATIONROOTDIRECTORY">

      <Component Id="tenlira.ini" Guid="*">
        <File Id="tenlira.ini" Source="..\ConfigurationFile\x64\tenlira.ini" KeyPath="yes" />
      </Component>

    </DirectoryRef>

    <Feature Id="MainApplication" Title="TenLira" Level="1">
      <ComponentRef Id="tenlira.ini" />
    </Feature>

  </Product>

</Wix>

它所做的只是简单地安装一个文件作为示例。到现在为止还挺好。现在,我要做的就是添加另一个ComponentFile当然也可以添加相应ComponentRef的 in Feature。我特别保留Version原样:31.00.0000。我所期望的是新安装程序不会执行重大升级,但它会执行。为什么?此外,现在添加/删除程序中有 2 个条目。

请帮我找出我在这里缺少什么。谢谢。雷菲尔。

更新:发布问题让我再次重新阅读文档,我发现元素中的AllowSameVersionUpgrades东西MajorUpgrade应该设置为yes. 这次添加/删除程序中只有一个条目,但它仍然执行主要升级。为什么?

4

3 回答 3

2

它进行了重大升级,因为两个 MSI 具有相同的 UpgradeCode 并且您现在指定了 AllowSameVersionUpgrades,因此它会在以前没有的地方进行升级。

您的构建每次都会生成一个新的 ProductCode,因此每个 MSI 都是一个新产品,因此如果它不进行升级,您将安装两次,如果升级,则安装一次。您可能对升级的工作方式有一些您没有说明的假设。

于 2018-02-12T18:32:58.723 回答
2

更新:这是一个列表,通过识别最常见的问题来帮助调试失败的主要升级:主要升级失败的常见原因


重大升级 - “旧的手动方式”

我猜你遇到了一个奇怪的问题,WiX MajorUpgrade 元素可能无法完全按照预期通过将auto-generated product GUIDAllowSameVersionUpgrades设置为yes并保持version number相同来处理。

我看不到在 WiX 的MajorUpgrade 元素中设置 MinInclusive 属性的任何明显方法——我可能弄错了,可能有一种我不知道的方法。对于它的价值,我不太热衷于允许“相同版本升级”。

但是,您可以尝试“使用旧方法”使用“旧元素” UpgradeUpgradeVersion 创建Upgrade 表。MajorUpgrade元素本质上是一种“方便”功能,可以轻松设置您的主要升级,我相信它适用于大多数用户。Bob Arnson 有一个博客解释了 MajorUpgrade 元素的引入。该博客还展示了如何使用“旧元素”“手动”执行操作的示例,并且(请检查一下)。UpgradeUpgradeVersion

我做了一个快速的模型,可以做你想要的,它只是一个“草稿”——不能做任何保证。我使用预处理器定义来设置一些可以在 WiX 源文件中引用的变量——作为 C++ 开发人员,这对你来说是小菜一碟,所以我不会浪费时间解释它——源代码应该是有意义的:

<?define MyProductVersion = "31.00.0000" ?>
<?define MyProductCode = "PUT-GUID-HERE" ?>
<?define MyUpgradeCode = "PUT-GUID-HERE" ?>

<!--Recommendation: set a path variable that you can redirect at will to a new release folder (new build output folder): -->

<!-- <?define MyBasePath = "C:\Projects\MyApp\Release\31.00.0000\" ?> -->

  <!-- SAMPLE: 
   <Component Win64="yes" Feature="MainApplication">
     <File Source="$(var.MyBasePath)\myapp.exe" />
   </Component> -->

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

  <Product Id="$(var.MyProductCode)" Codepage="1252" Language="1033" Manufacturer="Bla Corporation"
           Name="Bla" UpgradeCode="$(var.MyUpgradeCode)" Version="$(var.MyProductVersion)">

    <Package Comments="Contact: Refael Sheinker, refael.sheinker@bla.com." Description="Bla"
             InstallerVersion="500"
             Compressed="yes"
             InstallScope="perMachine"
             Keywords="Installer,MSI,Database" Languages="1033" Manufacturer="Bla Corporation" Platform="x64" />

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

   <!-- Major upgrade -->
    <Upgrade Id="$(var.MyUpgradeCode)">
      <!-- Downgrade Protection -->
      <UpgradeVersion Minimum="$(var.MyProductVersion)" OnlyDetect="yes" IncludeMinimum="yes" Property="DOWNGRADE_DETECTED"  />
      <!-- Major Upgrade Configuration -->
      <UpgradeVersion IncludeMinimum="no" Maximum="$(var.MyProductVersion)" IncludeMaximum="no" MigrateFeatures="yes" Property="UPGRADE_DETECTED"   />
    </Upgrade>

    <!-- Major Upgrade: Schedule RemoveExistingProducts -->
    <InstallExecuteSequence>
      <!-- Potential scheduling (after): InstallValidate, InstallInitialize, InstallExecute, InstallExecuteAgain, InstallFinalize -->
      <RemoveExistingProducts After="InstallInitialize" /> 
    </InstallExecuteSequence>

    <!--Launch Condition: Abort setup if higher version found-->
    <Condition Message="!(loc.NewerVersionDetected)">
      NOT DOWNGRADE_DETECTED
    </Condition>

    <Property Id="WIXUI_INSTALLDIR" Value="APPLICATIONROOTDIRECTORY" />
    <UIRef Id="WixUI_InstallDir" />

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFiles64Folder">
        <Directory Id="PROGRAMFILESSUBDIR" Name="Bla">
          <Directory Id="APPLICATIONROOTDIRECTORY" Name="BlaInternal" />
        </Directory>
      </Directory>
    </Directory>

    <DirectoryRef Id="APPLICATIONROOTDIRECTORY">

      <Component Id="Test.ini" Guid="PUT-GUID-HERE" Win64="yes" Feature="MainApplication">
        <CreateFolder Directory="APPLICATIONROOTDIRECTORY" />
        <IniFile Id="SomeSetting" Action="addLine" Directory="APPLICATIONROOTDIRECTORY" Key="Setting1" Name="Test.ini" Section="MySection" Value="Some Setting" />
        <IniFile Id="OtherSetting" Action="addLine" Directory="APPLICATIONROOTDIRECTORY" Key="Setting2" Name="Test.ini" Section="MySection" Value="Other Setting" />
      </Component>
   </DirectoryRef>

    <Feature Id="MainApplication" Title="TenLira" Level="1">
      <!--<ComponentRef Id="tenlira.ini" />-->
    </Feature>

  </Product>

</Wix>

现在!(loc.NewerVersionDetected)必须解释一下。这是一个本地化字符串(用于以不同语言提供您的设置)。要使用它,请在 Visual Studio 中右键单击您的 WiX 项目并转到:Add New Item... => Localization File => Add. 添加本地化文件后,您的输出 MSI 现在也将进入en-us主输出位置(调试或发布)下的文件夹。

在本地化文件中,添加:

<?xml version="1.0" encoding="utf-8"?>
<WixLocalization Culture="en-us" xmlns="http://schemas.microsoft.com/wix/2006/localization">
    <String Id="NewerVersionDetected">A later version of [ProductName] is already installed.</String>
</WixLocalization>

您现在应该能够向该文件添加新字符串,并使用此类语言文件轻松翻译您的整个设置。

还要添加 WiX GUI 扩展。Right click "References". Add Reference... => Browse to WixUIExtension.dll => Double click this file, and press OK. 找到文件的普通文件夹是:C:\Program Files (x86)\WiX Toolset v3.11\bin.


INI 文件

我只想提一下,INI 文件最好通过IniFile 表安装(条目被视为原子键值对,允许高级合并现有 INI 文件的键和值),而不是通过File 表(文件被处理作为常规文件,要么覆盖整个现有文件,要么将其保留在原位 - 不强制执行任何新值)。MSI IniFile 表对应的 WiX 元素自然是IniFile 元素

临时样本:

<Component Id="Test.ini" Guid="PUT-GUID-HERE" Win64="yes" Feature="MainApplication">
    <CreateFolder Directory="APPLICATIONROOTDIRECTORY" />
    <IniFile Id="SomeSetting" Action="addLine" Directory="APPLICATIONROOTDIRECTORY" Key="Setting1" Name="Test.ini" Section="MySection" Value="Some Setting" />
    <IniFile Id="OtherSetting" Action="addLine" Directory="APPLICATIONROOTDIRECTORY" Key="Setting2" Name="Test.ini" Section="MySection" Value="Other Setting" />
</Component>

链接

于 2018-02-13T06:53:07.443 回答
1

我在版本相同的情况下遇到了同样的问题,但是在添加/删除程序中创建多个条目时 ID 不同。我的简单解决方法是设置 AllowSameVersionUpgrades="yes"。

<MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of $(var.ServiceName) is already installed." />
于 2019-10-08T19:30:08.743 回答