简体   繁体   English

WiX,有条件地基于OS安装文件

[英]WiX, Conditionally installing a file based on OS

In my WiX project I need to install different content for the same file name, based on the OS. 在我的WiX项目中,我需要根据操作系统为同一文件名安装不同的内容。

  • If the OS is Windows 7 then the file needs to have content X. 如果操作系统是Windows 7,则文件需要具有内容X。
  • If the OS is Windows Vista the file needs to have content Y. 如果操作系统是Windows Vista,则文件的内容必须为Y。

I have thought through a few approaches: 我已经考虑了几种方法:

  1. Define two components, one with the content for windows 7 and another with the contents for Vista. 定义两个组件,一个包含Windows 7的内容,另一个包含Vista的内容。 Run a custom action based on the OS that overwrites the content for Vista if the OS is Windows 7. 如果操作系统是Windows 7,则基于操作系统运行自定义操作,该操作会覆盖Vista的内容。

  2. Define two additional features (window7 config and win vista config) have the components target the same file and install the feature conditionally based on OS. 定义两个附加功能(window7配置和win vista配置),使这些组件针对同一文件,并根据操作系统有条件地安装该功能。

Which is the best approach to take. 这是最好的方法。 Any tips, tricks and sample wix to get this going? 有任何提示,技巧和示例技巧可以使这种情况继续下去吗?

I'd do a slightly modified version of #1. 我将对#1做一个稍微修改的版本。 Have two Components. 有两个组成部分。 One Conditioned to install on Vista. 一种适合在Vista上安装。 The other Conditioned to install on Win7. 另一个条件是要在Win7上安装。 Then I'd have the appropriate file in the appropriate Component. 然后,我将在适当的组件中包含适当的文件。 No CustomAction necessary. 无需CustomAction。 CustomActions should be avoided at all costs, see: http://robmensching.com/blog/archive/2007/08/17/Zataoca-Custom-actions-are-generally-an-admission-of-failure.aspx 应不惜一切代价避免使用CustomAction,请参阅: http : //robmensching.com/blog/archive/2007/08/17/Zataoca-Custom-actions-are-generally-an-admission-of-failure.aspx

PS: Mark the Components Transitive so that the right content gets installed on an Operating System upgrade. PS:标记组件透明,以便在操作系统升级中安装正确的内容。

Another solution would be to install both files, and have the application read from the correct one at runtime. 另一种解决方案是安装两个文件,并在运行时从正确的文件中读取应用程序。 If this is a file that may be later modified by your application then you probably don't want to install it directly anyway, but rather install a "default" that is read if a "per user" file does not exist. 如果该文件稍后可能会被您的应用程序修改,则您可能不想直接安装它,而是安装一个“默认”文件,如果“每个用户”文件不存在,则会读取该文件。 In this case when a "per user" file does not exist, read the appropriate OS global defaults and then write those out to the "per user" file on first run (or whenever the particular file doesn't exist). 在这种情况下,当“每个用户”文件不存在时,请读取相应的操作系统全局默认值,然后在首次运行时(或在不存在特定文件时)将其写到“每个用户”文件中。

Sometimes what makes sense during the initial application design doesn't end up translating into a "good" Windows Installer result and you need to modify a few things :) 有时,在最初的应用程序设计中有意义的东西最终并没有转化为“好的” Windows Installer结果,您需要修改一些内容:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM