Wix 自定义操作 - session 为空且延迟操作时出错

标签 wix windows-installer wix3.11

我正在使用带有 VS2017 扩展的 Wix 3.11.1。我从自定义对话的控件中设置一个属性,然后尝试立即执行自定义操作。当我尝试阅读 session 时,它总是空的。

按照建议,我将我的操作更改为不同的执行,并使用立即操作来设置我的属性。当我运行安装程序时,出现错误:“调试:错误 2896:执行操作 [ActionName] 失败。”

在 CustomDialog.wxs 中

<Control Id="ConnId" Type="Edit" X="60" Y="110"  Height="17" Width="300" Property="CONN"/>

<Control Id="installButton" Type="PushButton" Text="Continue" Height="15" Width="60" X="240" Y="260">
      <Publish Event="DoAction" Value="RegistrationInfoCustomAction">1</Publish>
      <Publish Event="EndDialog" Value="Return">1</Publish>
    </Control>

<Fragment>
<Binary Id="CustomActionBinary" SourceFile="..\..\CustomActions\bin\Debug\CustomActions.CA.dll"/>
<CustomAction Id="SetPropertyForShowProperty" Property="RegistrationInfoCustomAction" Execute="immediate" Value="[CONN]" Return="check" />
<CustomAction Id="RegistrationInfoCustomAction" BinaryKey="CustomActionBinary" DllEntry="SaveUserInfo" Execute="deferred" Return="check" HideTarget="no"/>
</Fragment>

在 Product.wxs 中

<InstallExecuteSequence>
<Custom Action="SetPropertyForShowProperty" After="InstallInitialize"/>
<Custom Action="RegistrationInfoCustomAction" Before="InstallFinalize"/>
</InstallExecuteSequence>

在 CustomActions.cs 中

[CustomAction]
    public static ActionResult SaveUserInfo(Session session)
    {
        Debugger.Launch();
        CustomActionData data = session.CustomActionData;

        session.Log("Begin SaveUserInfo");
        var connectionString = data["CONN"];
        session.Log($"content: {connectionString}");

        session.Log("End SaveUserInfo");
        return ActionResult.Success;
    }

当自定义操作仅包含日志语句但添加任何其他代码会使它失败时,它会起作用。此外, session 始终为空。

在安装程序日志中:

MSI (c) (88:34) [16:30:21:255]:调用远程自定义操作。 DLL:C:\Users\Andre\AppData\Local\Temp\MSIF1A3.tmp,入口点:SaveUserInfo

MSI (c) (88:F8) [16:30:21:256]:启用伪装。

MSI (c) (88:F8) [16:30:21:256]:在调用 Install on Server 之前尝试启用所有禁用的权限

MSI (c) (88:F8) [16:30:21:256]:连接到 CA 接口(interface)服务。

操作于 16:30:41 结束:RegistrationInfoCustomAction。返回值 3.

调试:错误 2896:执行操作 RegistrationInfoCustomAction 失败。

安装程序在安装此包时遇到意外错误。这可能表明此包存在问题。错误代码为 2896。 参数是:RegistrationInfoCustomAction, , 操作结束 16:30:41:SetupDialog。返回值 3。 MSI (c) (88:8C) [16:30:41:911]:执行操作:FatalError

最佳答案

类似答案:我想添加一些链接到之前关于延迟模式自定义操作主题的答案。这些答案中有指向 github-samples 的链接——包括一个使用 DTF class CustomActionData 的示例轻松将属性发送到延迟模式(正确设置后):


UPDATE: It is late, I didn't see this on first sight, but only immediate mode custom actions can be run from the setup GUI. Make a new, immediate mode custom action to set a value to your PUBLIC property CONN, and then set the value of CONN via a type 51 custom action to be assigned to the Id of the deferred mode custom action - as described below.


SecureCustomProperties: Add the property you specify to SecureCustomProperties by setting the Secure="yes" attribute:

<Property Id="MYPROPERTY" Secure="yes">Send this text to deferred mode</Property>

Name Match: the property name you assign the value to must match the deferred mode custom action Id. Looks OK in your source.

更多技术:type 51 actionProperty 属性值 必须与使用 CustomActionData 的自定义操作:

<!-- Declare property with value -->
<Property Id="MYPROPERTY" Secure="yes">Send this text to deferred mode</Property>

<!-- Type 51 CA: Send value of MYPROPERTY to the deferred mode CA named MyAction -->
<CustomAction Id="MyAction.SetProperty" Return="check" Property="MyAction" Value="[MYPROPERTY]" />

<!-- The deferred mode custom action -->
<CustomAction Id="MyAction" Return="check" Execute="deferred" BinaryKey="CAs" DllEntry="MyAction" />

<!-- ... -->

<!-- Inserting the CAs in sequence -->
<InstallExecuteSequence>
    <Custom Action="MyAction.SetProperty" After="InstallInitialize" />
    <Custom Action="MyAction" Before="InstallFinalize" />
</InstallExecuteSequence>

这里有一些资源:


Just for debugging reference .你可以使用:string data = session["CustomActionData"];


告诉您,让我滑入代码以使用 VBScript 进行测试,以便您可以使用消息框。应该不是必需的,以防万一您遇到调试问题:

VBScript “Simple.vbs”(另存为文件):

MsgBox Session.Property("CustomActionData")

WiX 标记更改:

<Binary Id='Simple.vbs' SourceFile='Simple.vbs' />
<CustomAction Id="MyAction" Return="check" Execute="deferred" BinaryKey="Simple.vbs" VBScriptCall='' />

以防万一这更容易。建议您仅使用 VBScript 进行调试。当我想消除所有其他错误源时,我喜欢 VBScript 获得“心跳”。

关于Wix 自定义操作 - session 为空且延迟操作时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54285093/

相关文章:

wix - Wix中如何设置Checkbox默认选中

wix - 如何调试自定义引导应用程序?

python - PTVS 未检测到已安装的 VS2010

使用属性值的 WIX 自定义操作条件不起作用

Wix 安装程序不会覆盖以前版本的可执行文件

wix - 代码签名的 MSI 名称问题,WiX

installation - 从合并模块中提取文件

windows - 调试 "service failed to start"Windows Installer 错误

c# - 使用 WIX 安装程序安装 .NET Framework 4.7.2(如果需要)