我想在安装过程中显示我的自定义操作的进度文本。我在 WiX Progress Text for a Custom Action 中实现了代码但它不起作用。
显示所有其他文本(例如文件副本),正确填充 ActionText 表并且 ActionText.Action 匹配 CustomAction.Actuib 值。有谁知道出了什么问题?这是代码:
WiX 主要项目:
<Product>
<CustomAction Id="MyCA" BinaryKey="MyCALib"
DllEntry="MyCAMethod" Execute="deferred"
Return="check" />
<InstallExecuteSequence>
<Custom Action="MyCA" Before="InstallFinalize" />
</InstallExecuteSequence>
<UI>
<UIRef Id="MyUILibraryUI" />
</UI>
</Product>
用户界面库:
<Wix ...><Fragment>
<UI Id="MyUILibraryUI">
<ProgressText Action="MyCA">Executing my funny CA...
</ProgressText>
...
<Dialog Id="Dialog_Progress" ...>
<Control Id="Ctrl_ActionText"
Type="Text" ...>
<Subscribe Event="ActionData" Attribute="Text" />
</Control>
...
C# 自定义 Action 库:
public class MyCALib
{
[CustomAction]
public static ActionResult MyCAMethod(Session session)
{
System.Threading.Thread.Sleep(10000); // to show text
// do something
System.Threading.Thread.Sleep(10000); // to show text
return ActionResult.Success;
}
}
最佳答案
问题是您正在使用“ActionData”,但您没有使用来自自定义操作的此操作数据向 UI 发送消息。
您必须添加如下内容:
public class MyCALib
{
[CustomAction]
public static ActionResult MyCAMethod(Session session)
{
using (Record record = new Record(0))
{
record.SetString(0, "Starting MyCAMethod");
Session.Message(InstallMessage.ActionData, record);
}
System.Threading.Thread.Sleep(10000); // to show text
// do something
System.Threading.Thread.Sleep(10000); // to show text
return ActionResult.Success;
}
}
您可以根据需要从 CA 发送任意数量的消息。
如果您使用的是“ActionText”,它将起作用,但会显示自定义操作名称,而无需附加/自定义信息。
您将在此处找到更多信息:
WiX: dynamically changing the status text during CustomAction
关于wix - ProgressText 不适用于 WiX 中的自定义操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17221402/