如何使用 Wix 工具集在 Majorupgrade 期间显式删除 dll [英] How to Explicitly Remove dll During Majorupgrade Using Wix Toolset

查看:14
本文介绍了如何使用 Wix 工具集在 Majorupgrade 期间显式删除 dll的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在尝试为我们的产品部署更新,其中包含更新的 dll.这个 dll 也有一个版本号,所以通常安装程序应该能够看到它并替换旧的 dll.

We are trying to deploy an update to our product which contains an updated dll. This dll also has a version number so normally the installer should be able to see this and replace the old dll.

Windows 安装程序在检查版本号时只关心前三个数字.然而,在这种情况下,更新的版本号看起来相同,除了第四个数字.因此,例如,如果前一个 hade 1.0.0.12 这有 1.0.0.20 因此安装程序将它们视为相同版本并且不会替换文件.在这种情况下,我无法控制版本编号,而且由于我们包含了很多 dll,这在未来可能会再次发生.

Windows installer only cares about the first three numbers when checking version number. However in this case the updated version number looks the same save for the fourth number. So for example if the previous one hade 1.0.0.12 this has 1.0.0.20 hence the installer see them as the same version and does not replace the file. I have no control over the version numbering in this case and since we include a lot of dlls this could happen again in the future.

无论版本号是否相同,如何让安装程序替换文件?

How would one go about making the installer replace the file no matter if the version number is the same?

在搜索了不同的解决方案后,我试图告诉安装程序在安装过程中删除该文件.如果没有必要,我不想删除所有文件.到目前为止,我已经尝试了包含的代码片段中所示的解决方案.removefile 元素在此版本的安装程序中是新的.

After searching for different solutions I have tried to tell the installer to remove the file during the install process. I do not want to remove all files if not necessary. So far I have tried the solution as showed in the included code snippet. The removefile element is new in this version of the installer.

<Component Id="SomeComponent" Win64="yes" Guid="*">
<File Id="SomeFile" KeyPath="yes" Source="$(var.app.TargetDir)some.dll" />
<RemoveFile Id="RemoveSomeFile" Name="some.dll" On="install"/>
</Component>

我期望的结果是旧的 dll 被新的 dll 替换,但是安装后旧的 dll 仍然存在并且没有新的.

The result i expect is for the old dll to be replaced by the new dll however after install the old dll is still there and no new one.

推荐答案

类似答案:未安装新组件的文件,因为旧组件具有相同的文件

<小时>

配套文件:如何使用 WiX 中的配套文件 - 只是一个片段(调试后发现 OP需要降级文件而不是版本位数问题 - 非常常见的问题):


Companion Files: How to use Companion Files in WiX - just a snippet (after debugging it was discovered that OP had an issue of needing to downgrade files instead of a problem with number of version digits - very common issue):

<..>

<Component Id="MyFile.exe" Feature="Main">
  <File Id="MyFile.exe" Source="MyFile.exe"></File>
</Component>

<Component Id="MyFile_2.exe" Guid="{0EBDFD64-017B-428F-BB67-3D82EA2A99AF}" Feature="Main">
  <File Source="MyFile_2.exe" CompanionFile="MyFile.exe"></File>
</Component>

<..>

单行摘要:在第二个组件中,我们指向第一个组件的文件,以便在安装 MyFile.exe 时安装 MyFile_2.exe - 无论版本如何问题.

One-Line Summary: In the second component we point to the first component's file so that MyFile_2.exe will install whenever MyFile.exe is installed - regardless of versioning issues.

下面的旧答案供参考和可用于测试的 WiX 源.

Older answer below left in for reference and the WiX source that can be used for testing.

MSI 版本:Windows 安装程序在检查版本号时只关心前三个数字.

MSI Version: Windows installer only cares about the first three numbers when checking version number.

文件版本与产品版本:上述说法通常是正确的,但据我所知(并基于快速冒烟测试),这个 3 位数限制仅适用于 MSI 的 ProductVersion(MSI 本身的版本),而不是实际的文件版本号.

File Version vs ProductVersion: The above statement is generally correct, but to the best of my knowledge (and based on a quick smoke test), this 3-digit restriction only applies to the MSI's ProductVersion (the version of the MSI itself), and not to actual file version numbers.

文件版本以 4 位数字表示,而不是 3 位数字MSI 的ProductVersion(MSI 的版本本身).请自己进行测试以确保.示例 WiX 标记以在下面执行此操作.

File versions are respected in 4 digits, as opposed to the 3 digit limit for the MSI's ProductVersion (the version for the MSI itself). Please run a test yourself to be sure. Sample WiX markup to do so below.

<小时>

REINSTALLMODE:文件覆盖修饰符机制REINSTALLMODE可用于强制覆盖文件,无论版本如何.不得使用此机制,因为它会导致许多问题:在早期版本的 Windows 中,不必要的重启提示、系统共享文件降级、导致某些文件升级而其他文件不升级(新旧软件包安装顺序不正确)尝试降级受保护文件等导致崩溃...


REINSTALLMODE: The file-overwrite modifier mechanism REINSTALLMODE can be used to force overwrite files regardless of version. This mechanism must not be used since it can cause a number of problems: unnecessary reboot prompts, downgrading of system shared files, cause some files to be upgraded and others not (old and new packages installed out of sequence), in earlier versions of Windows crashes as protected files are attempted downgraded, etc...

WiX Mockup 测试源:我将在此处转储一个简单的 WiX 测试源以帮助您快速测试(例如,在不同的操作系统版本上,我在 Windows 上进行了测试10):

WiX Mockup Test Source: I'll dump a simple test WiX source here to help you test this quickly (on different OS versions for example, I tested on Windows 10):

顺便说一下,由于本产品的一些固有设计特点示例,它还将说明重大升级失败时您只提高 4 位版本号的最后一位,但文件覆盖将起作用.安装第 2 版时,您会在添加/删除程序"中找到两个产品条目.这是基于样本设计的预期结果.只需卸载两者.

Incidentally, due to some inherent design characteristics of this sample, it will also illustrate that major upgrades fail when you only bump up the last digit of the 4-digit version number, but file overwrites will work. When you install version 2, you will find two product entries in Add / Remove Programs. This is expected based on the design of the sample. Just uninstall both.

<?define MyVersion = "1.0.0.0" ?>
<?define MyReleasePath = "$(sys.SOURCEFILEDIR)_Files$(var.MyVersion)" ?>

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

  <Product Id="*" Name="FileVersioning" Language="1033" Version="$(var.MyVersion)"
           Manufacturer="FileVersioning" UpgradeCode="{4864AA4A-EA1D-4367-8427-85D296B0A2A6}">

    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

    <MediaTemplate EmbedCab="yes" />
    <Feature Id="Main" Title="FileVersioning" Level="1" />

    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="FileVersioning">
          <Component Feature="Main">
            <File Source="$(var.MyReleasePath)MyTestFile.exe"></File>
          </Component>
        </Directory>
      </Directory>
    </Directory>
  </Product>

</Wix>

使用:

  1. 创建 WiX 项目,用上述标记替换模板内容.
  2. 在 WiX 项目文件夹中创建一个名为 _Files 的子文件夹,并在该文件夹下创建另外两个子文件夹,其中包含相同文件的两个版本,如下图所示.
    • 快速方法:在 Visual Studio 中,右键单击 WiX 项目并选择 在文件资源管理器中打开文件夹 以进入 WiX 项目文件夹很快.
    • 现在粘贴两个文件夹或创建它们.
    • 您可以在 Visual Studio 中打开 EXE 以破解"版本号,以便在具有不同版本号的两个文件夹中使用相同的 EXE 或 DLL.有关信息,请参阅以下部分.
  1. Create WiX project, replace template content with above markup.
  2. Make a sub-folder in WiX project folder called _Files and two further sub folders under there with two versions of the same file as illustrated below.
    • Quick Way: In Visual Studio, right click the WiX project and select Open Folder in File Explorer to get to the WiX project folder quickly.
    • Now paste in two folders or create them.
    • You can open the EXE in Visual Studio to "hack" the version number so you use the same EXE or DLL in both folders with different version numbers. See section below for information.

版本化文件的文件夹结构(在主项目文件夹中创建):

Folder structure for versioned files (create inside main project folder):

_Files
   23.4.5.2MyTestFile.exe
   23.4.5.3MyTestFile.exe

<小时>

将 EXE 作为资源打开:在 Visual Studio 中试试这个:


Open EXE as Resource: In Visual Studio try this:

  1. File => 打开 => File
  2. 浏览版本化文件(EXEDLL等..)
  3. 单击版本化文件一次(且仅一次)
  4. 点击打开按钮的向下箭头=> 打开方式...
  5. 选择Resource Editor并打开文件.
  6. 找到版本部分,打开并双击条目.
  7. 更改版本号,保存新文件版本(不在现有版本之上).

<小时>

链接:

这篇关于如何使用 Wix 工具集在 Majorupgrade 期间显式删除 dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆