如何在主要升级期间使用Wix Toolset明确删除dll [英] How to Explicitly Remove dll During Majorupgrade Using Wix Toolset

查看:83
本文介绍了如何在主要升级期间使用Wix Toolset明确删除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安装程序在检查版本号时仅关心前三个数字.但是,在这种情况下,更新的版本号看起来与第四个数字相同.因此,例如,如果先前的版本具有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仍然存在,并且没有新的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.

文件版本与ProductVersion :上面的陈述通常是正确的,但据我所知(基于快速冒烟测试),该3位数字限制仅适用于MSI的 ProductVersion (MSI本身的版本),而不是实际的 file version numbers .

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样机测试源 :我将在此处转储一个简单的测试WiX源,以帮助您快速进行测试(例如,在不同的OS版本上,我在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>

用法 :

Usage:

  1. 创建WiX项目,用上面的标记替换模板内容.
  2. 在WiX项目文件夹中创建一个名为 _Files 的子文件夹,并在该文件夹下另外创建两个带有相同版本的文件的子文件夹,如下所示.
    • 快捷方式 :在Visual Studio中,右键单击WiX项目,然后选择Open Folder in File Explorer以快速进入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.2\MyTestFile.exe
   23.4.5.3\MyTestFile.exe


打开EXE作为资源 :在Visual Studio中,请尝试以下操作:


Open EXE as Resource: In Visual Studio try this:

  1. File => Open => File
  2. 浏览版本文件( EXE DLL etc... )
  3. 一次(仅一次)单击版本控制文件
  4. 单击 Open 按钮的向下箭头=> Open With...
  5. 选择 Resource Editor 并打开文件.
  6. 找到 Version section ,打开并双击条目.
  7. 更改版本号,保存新文件版本(不在现有文件的顶部).
  1. File => Open => File
  2. Browse for a versioned file (EXE, DLL, etc...)
  3. Click versioned file once (and only once)
  4. Click the down arrow for the Open button => Open With...
  5. Select Resource Editor and open file.
  6. Locate Version section, open and double click entry.
  7. Change version numbers, save new file version (not on top of existing).


链接 :


Links:

  • WIX (remove all previous versions)
  • Forcing an upgrade of a file that is modified during its initial installation

这篇关于如何在主要升级期间使用Wix Toolset明确删除dll的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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