Osc*_*car 2 windows-installer wix wix3.5
我正在尝试按照以下答案在默认 wix 的 ProgressDlg 中显示自定义状态消息:
到目前为止,我在我的自定义操作中得到了这个代码:
public class CustomActions
{
[CustomAction]
public static ActionResult CustomAction1(Session session)
{
Debugger.Launch();
session.Log("Begin CustomAction1");
MessageTest(session);
return ActionResult.Success;
}
private static void MessageTest(Session session)
{
for (int i = 0; i < 10; i++)
{
using (Record r = new Record(0))
{
r.SetString(0, $"Hello worls {i}");
session.Message(InstallMessage.ActionData, r);
}
Thread.Sleep(1000);
}
}
}
Run Code Online (Sandbox Code Playgroud)
然后,在 Product.wxs 中有以下 xml 片段:
<Binary Id="CuCustomInstallActionsBinary" SourceFile="$(var.ConsoleApplication1_TargetDir)CustomAction1.CA.dll" />
<CustomAction Id="CuCustomActionOnAfterInstall" BinaryKey="CuCustomInstallActionsBinary" DllEntry="CustomAction1" Execute="deferred" HideTarget="no" Return="check" Impersonate="no" />
<InstallExecuteSequence>
<Custom Action="CuCustomActionOnAfterInstall" Before="InstallFinalize"><![CDATA[(NOT Installed) AND (NOT REMOVE)]]></Custom>
</InstallExecuteSequence>
Run Code Online (Sandbox Code Playgroud)
但是在 UI 中没有显示任何内容。自定义操作运行时,状态消息保持为空。
还有什么应该做的来完成这个吗?也许订阅<Subscribe Event="ActionData" Attribute="Text" />我是否必须为此实现我自己的自定义 ProgressDlg?
我在@jbudreau 提示后找到了答案。该Record实例必须有3场,这是相同数量的ActionText MSI表列。第一个字段必须设置为自定义操作名称,第二个是要显示的 UI 消息,第三个是模板值,在我的例子中没有使用。此外,调用session.Message()必须包含参数InstallMessage.ActionStart。所以,最终的代码是:
public void UpdateStatus(string message)
{
using (Record r = new Record(3))
{
r.SetString(1, "CuCustomActionOnAfterInstall");
r.SetString(2, message);
session.Message(InstallMessage.ActionStart, r);
}
}
Run Code Online (Sandbox Code Playgroud)
我还没有测试是否有必要在 ActionText 中有一个条目,这是通过在 Product.wxs 文件中放置 Product 标签内的 ProgressText 来完成的。没有这个,生成的 MSI 文件将不包含 ActionText 表
<UI>
<ProgressText Action="CuCustomActionOnAfterInstall">Running post install configuration.</ProgressText>
</UI>
Run Code Online (Sandbox Code Playgroud)