在WiX中运行自定义操作之前设置环境变量 [英] Set environment variable before running a custom action in WiX

查看:160
本文介绍了在WiX中运行自定义操作之前设置环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须使用 MSI 的安装程序。 /en.wikipedia.org/wiki/WiX rel = nofollow> WiX ,我需要在运行命令操作之前将环境设置为 MY_HOME

I have to build an MSI-based installer using WiX and I need to set environment MY_HOME before running a command action.

我有一个组件:

<Component Id="SEMYHOME"
           Guid="*my guid*">
    <CreateFolder />
    <Environment Id="MY_HOME"
                 Action="set"
                 Part="all"
                 Name="MY_HOME"
                 Permanent="no"
                 System="yes"
                 Value="[APPLICATIONPATH]myapp"/>
</Component>

然后我有一个自定义操作:

Then I have a custom action:

<CustomAction Id="InstallMyService"
              Directory="INSTALLDIR"
              ExeCommand='&quot;[INSTALLDIR]myapp\install_service.bat&quot; install'
              Execute="immediate"
              Return="ignore"/>
<InstallExecuteSequence>
    <Custom Action="InstallMyService"
            After="InstallFinalize"/>
</InstallExecuteSequence>

注意:此操作需要 MY_HOME 变量

在安装此MSI时,我看到一条日志,显示已设置 MY_HOME 变量在运行自定义操作 InstallMyService之前,但是安装我的服务的命令仍然失败。我发现原因是调用命令时仍未设置MY_HOME。

When install this MSI, I got a log showing that the MY_HOME variable is set before running the custom action "InstallMyService", but the command to install my service still fails. I found that the cause is when command called, MY_HOME still not set.

安装完成后,MY_HOME已按预期设置,但自定义操作失败:(

After an install is finished, MY_HOME was set as expected, but the custom action fails :(

如何解决此问题?

推荐答案

Windows Installer和Custom动作是通过服务控制管理器托管的,该服务控制器历史悠久,不尊重宣布环境变化而发送的广播消息,因此,即使您解决了Yan提到的即时/延迟问题,您仍会发现自定义动作仍然没有

Windows Installer and Custom Actions are hosted via the Service Control Manager which has a long history of not respecting broadcast messages that are sent announcing Environment changes. So even if you fix the immeadiate / deferred problem that Yan mentions you'll find that your custom action still doesn't have the environment variable.

为什么不只是将 [APPLICATIONPATH] myapp传递到您的.bat文件并以%2的形式获取它?

Why don't just just pass "[APPLICATIONPATH]myapp" to your .bat file and fetch it in as %2?

顺便说一句,我也不建议从安装程序中调用批处理文件。看到弹出的安装弹出黑色小窗口,这是脆弱而令人尴尬的。

BTW I also don't reccomend calling batch files from an installer. It's fragile and embarrassing to see installs that run popping up little black windows.

这篇关于在WiX中运行自定义操作之前设置环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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