使用WiX自定义操作来设置属性的值 [英] Using a WiX custom action to set a property's value

查看:165
本文介绍了使用WiX自定义操作来设置属性的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在修改现有的 WiX 安装程序,以处理更新其中一项产品的现有安装。有几个值的默认值在属性中指定。这些属性显示给用户进行编辑,然后由现有安装程序写入到自定义配置文件中。

I am modifying an existing WiX installer to handle updating an existing installation of one of our products. There are several values whose defaults are specified in properties. These properties are displayed to the user for editing and are then written to a custom configuration file by the existing installer.

我的代码需要足够聪明才能检测出是否进行全新安装与安装旧版本。如果要进行全新安装,则需要将属性设置为默认值。但是,如果要进行升级,则代码需要从现有配置文件中检索那些属性的值,并将这些值显示给用户。

My code needs to be smart enough to detect if it is doing a brand new install versus installing an older version. If it is doing a brand new install, it needs to set the properties to default values. But if it is doing an upgrade, the code needs to retrieve the valus of those properties from the existing configuration file and display those to the user.

完成后,在我看来我需要使用键入51自定义操作来设置属性。但是我该如何实现此自定义操作?

From the reading I've done, it seems to me I need to use a type 51 custom action to set the properties. But how do I implement this custom action?

我在想,我必须先定义自定义操作才能将其放入自定义操作表中,然后我需要将标签贴在某处进行调用。然后我需要定义它。

I'm thinking that I have to first define the custom action to put it in the custom action table, and then I need to stick a tag somewhere to call it. And then I need to define it.

我该怎么做?

推荐答案

在对自定义动作进行了更多研究之后,我相信我已经掌握了所有这些东西想通了。我在.wxs文件中添加了一个< Binary>标记,以标识该自定义操作所在的位置。然后,我在CustomAction中引用了Binary标签的ID。最后,我在InstallExecuteSequence部分中添加了一个Custom标签,该ID通过ID引用了CustomAction标签。

After doing some more research into custom actions, I believe I've got all of this figured out. I added a <Binary> tag to the .wxs file to identify where the custom action resides. I then referenced the Binary tag's ID in the CustomAction. Finally, I added a Custom tag to the InstallExecuteSequence section that referenced the CustomAction tag by ID.

上面提到的最后一个Custom标签需要进入InstallUISequence部分,而不是InstallExecuteSequence部分,因为需要在显示对话框之前调用自定义操作。

The final Custom tag mentioned above needs to go into the InstallUISequence section, not the InstallExecuteSequence section, as the custom action needs to be called before the dialog is displayed.

关于自定义操作本身的实现,我添加了一个新的C#自定义操作库项目解决方案。在其中,我实现了一种方法,该方法以[CustomAction]属性装饰。此方法使用作为参数传递给该方法的Session对象中存储的属性值,并确定当前版本的可执行文件的路径。然后,它会执行所需的工作,以在程序的配置文件中找到需要在各个版本之间保留的值,并将其写入升级脚本的其他属性。

As for the implementation of the Custom Action itself, I added a new C# Custom Action library project to the solution. In there, I implemented a method, decorated with the [CustomAction] attribute. This method uses the values of properties stored in the Session object passed as a parameter to the method and determines the path of the current version's executable file. It then does the work needed to locate the values in the program's Configuration file that need to be preserved across versions and writes them to other properties for the upgrade script.

这篇关于使用WiX自定义操作来设置属性的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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