使用 WiX 自定义操作设置属性值

发布于 2024-12-04 07:07:25 字数 519 浏览 2 评论 0原文

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

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

从我完成的阅读来看,在我看来我需要使用 键入 51 自定义操作 以设置属性。但是我如何实现这个自定义操作呢?

我想我必须首先定义自定义操作以将其放入自定义操作表中,然后我需要在某处粘贴一个标签来调用它。然后我需要定义它。

我该怎么做?一些示例代码是什么?

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.

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.

How can I do this? What would some example code be?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

亽野灬性zι浪 2024-12-11 07:07:25

在对自定义操作进行了更多研究之后,我相信我已经弄清楚了所有这些。我添加了一个标记到 .wxs 文件以标识自定义操作所在的位置。然后我在 CustomAction 中引用了二进制标签的 ID。最后,我向 InstallExecuteSequence 部分添加了一个 Custom 标记,该标记按 ID 引用 CustomAction 标记。

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

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

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.

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.

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.

治碍 2024-12-11 07:07:25

例子:

    [CustomAction]
    public static ActionResult SetProperty(Session session)
    {
        try
        {
            session.Log("Begin SetProperty action");

            session["PROPERTY_NAME"] = "value"


        }
        catch (Exception exception)
        {
            session.Log("ERROR in custom action SetProperty {0}", exception.ToString());

            return ActionResult.Failure;
        }

        return ActionResult.Success;
    }

Example:

    [CustomAction]
    public static ActionResult SetProperty(Session session)
    {
        try
        {
            session.Log("Begin SetProperty action");

            session["PROPERTY_NAME"] = "value"


        }
        catch (Exception exception)
        {
            session.Log("ERROR in custom action SetProperty {0}", exception.ToString());

            return ActionResult.Failure;
        }

        return ActionResult.Success;
    }
俏︾媚 2024-12-11 07:07:25

阅读 WiX 教程的以下部分:

  1. 额外操作:概述如何向 MSI 添加自定义操作;
  2. 书中没有的内容 :提供了如何在 DLL 中实现自定义操作的示例。

Read the following sections of WiX tutorial:

  1. Extra Actions: gives an overview of how to add a Custom Action to MSI;
  2. What's Not in the Book: provides an example how to implement a Custom Action in DLL.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文