如何创建自定义操作并将其链接到我的 WiX 设置项目?
我有:
最佳答案
您需要创建一个新的适用于 WiX v3 的 C# 自定义操作项目 在您的解决方案中。
这应该是这样的:
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
namespace CustomAction
{
public class CustomActions
{
[CustomAction]
public static ActionResult CustomAction(Session session)
{
session.Log("Begin CustomAction");
return ActionResult.Success;
}
}
}
将函数名称更改为适合您的函数的名称。
之后右键单击引用资料夹 在您的 WiX 设置项目上并选择 添加引用... .
点击标签项目 并选择您的自定义操作项目。对于最后一步,您需要将此代码添加到您的 Product.wxs:
<Binary Id="CustomActionBinary" SourceFile="$(var.CUSTOMACTIONSNAME.TargetDir)$(var.CUSTOMACTIONSNAME.TargetName).CA.dll" />
<CustomAction Id="CUSTOMACTIONAME" Impersonate="no" BinaryKey="CustomActionBinary" DllEntry="CUSTOMACTIONFUNCTION" Return="check" />
您只需在此处更改几个名称:
就是这样。
如果您现在想在安装项目中调用自定义操作,您只需要创建一个带有 Action 属性的“自定义”元素,并将您的自定义操作 ID 作为值,如下所示:
<Custom Action="CreateConfig" ... />
您可以将自定义操作插入到 UI 序列或安装序列中,如下所示:
<!--User Interface Sequence-->
<InstallUISequence>
<Custom Action='CustomAction1' Before='ExecuteAction' />
</InstallUISequence>
<!--Installation Sequence-->
<InstallExecuteSequence>
<Custom Action='CustomAction1' After='InstallInitialize'>NOT Installed</Custom>
</InstallExecuteSequence>
您还可以从对话框中的事件调用自定义操作(仅片段 - 有点涉及):
<...>
<Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="&Next">
<Publish Event="DoAction" Value="CustomAction1">1</Publish>
<...>
关于c# - 如何在 c# 中创建自定义操作并将其绑定(bind)到 wix 设置项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54144994/