如何创建自定义操作并将其链接到我的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属性的“ Custom”元素,并将您的自定义操作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>
<...>
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句