Wix 自定义操作 - 会话为空且延迟操作时出错
Wix Custom Action - session empty and error on deferred action
我正在使用带有 VS2017 扩展的 Wix 3.11.1。我从自定义对话的控件中设置了 属性,然后尝试立即执行自定义操作。当我尝试阅读会话时,它总是空的。
按照建议,我将我的操作更改为不同的执行,并使用立即操作来设置我的 属性。当我 运行 我的安装程序出现错误时: "DEBUG: Error 2896: Executing action [ActionName] failed."
在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;
}
自定义操作在仅包含日志记录语句但添加任何其他代码会使它失败时有效。另外,会话总是空的。
在安装程序日志中:
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]:在服务器上调用安装之前尝试启用所有禁用的权限
MSI (c) (88:F8) [16:30:21:256]: 已连接到 CA 接口服务。
操作结束16:30:41:RegistrationInfoCustomAction。 Return 值 3.
调试:错误 2896:执行操作 RegistrationInfoCustomAction 失败。
安装程序在安装此包时遇到意外错误。这可能表明此包存在问题。错误代码为 2896。
参数是:RegistrationInfoCustomAction, ,
操作结束 16:30:41:SetupDialog。 Return 值 3。
MSI (c) (88:8C) [16:30:41:911]:执行操作:FatalError
类似答案:我想添加一些链接到之前关于延迟模式自定义操作主题的答案。这些答案中有 github-samples 的链接——包括一个使用 DTF class CustomActionData 轻松将属性发送到延迟模式的示例(一旦您正确设置):
Pass ConnectionString to Custom Action in WiX Installer (escape semicolon)
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 action
的 the Property attribute's value
必须与自定义操作的 ID 相同正在消耗 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>
这里有一些资源:
- How to pass CustomActionData to a CustomAction using WiX?
- https://www.firegiant.com/wix/tutorial/events-and-actions/at-a-later-stage/
- How to access installer properties from deferred custom actions
- Accessing or Setting Windows Installer Properties Through Deferred, Commit, and Rollback Custom Actions
. And you can use: 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 得到一个“heartbeat
”。
我正在使用带有 VS2017 扩展的 Wix 3.11.1。我从自定义对话的控件中设置了 属性,然后尝试立即执行自定义操作。当我尝试阅读会话时,它总是空的。
按照建议,我将我的操作更改为不同的执行,并使用立即操作来设置我的 属性。当我 运行 我的安装程序出现错误时: "DEBUG: Error 2896: Executing action [ActionName] failed."
在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;
}
自定义操作在仅包含日志记录语句但添加任何其他代码会使它失败时有效。另外,会话总是空的。
在安装程序日志中:
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]:在服务器上调用安装之前尝试启用所有禁用的权限
MSI (c) (88:F8) [16:30:21:256]: 已连接到 CA 接口服务。
操作结束16:30:41:RegistrationInfoCustomAction。 Return 值 3.
调试:错误 2896:执行操作 RegistrationInfoCustomAction 失败。
安装程序在安装此包时遇到意外错误。这可能表明此包存在问题。错误代码为 2896。 参数是:RegistrationInfoCustomAction, , 操作结束 16:30:41:SetupDialog。 Return 值 3。 MSI (c) (88:8C) [16:30:41:911]:执行操作:FatalError
类似答案:我想添加一些链接到之前关于延迟模式自定义操作主题的答案。这些答案中有 github-samples 的链接——包括一个使用 DTF class CustomActionData 轻松将属性发送到延迟模式的示例(一旦您正确设置):
Pass ConnectionString to Custom Action in WiX Installer (escape semicolon)
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 action
的 the Property attribute's value
必须与自定义操作的 ID 相同正在消耗 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>
这里有一些资源:
- How to pass CustomActionData to a CustomAction using WiX?
- https://www.firegiant.com/wix/tutorial/events-and-actions/at-a-later-stage/
- How to access installer properties from deferred custom actions
- Accessing or Setting Windows Installer Properties Through Deferred, Commit, and Rollback Custom Actions
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 得到一个“heartbeat
”。