[英]How to create custom actions in c# and bind it on a wix setup project
How do I create custom actions and link it to my WiX setup project? 如何创建自定义操作并将其链接到我的WiX安装项目?
I have: 我有:
You need to create a new C# Custom Action Project for WiX v3 in your solution. 您需要在解决方案中为WiX v3创建一个新的C#自定义操作项目 。
That should look like this: 看起来应该像这样:
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;
}
}
}
Change the function name to a name that fits your function. 将函数名称更改为适合您的函数的名称。
After that right click on the References Folder on your WiX setup project and choose Add Reference... . 之后,右键单击WiX设置项目上的References文件夹 ,然后选择Add Reference ...。
Click the tab Projects and choose your custom action Project. 单击选项卡项目,然后选择您的自定义操作项目。
For the last step you need to add this code to your Product.wxs: 对于最后一步,您需要将此代码添加到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" />
You only need to change a few names here: 您只需要在此处更改一些名称:
Thats it. 而已。
If you now want to call the custom action in your setup project, you only need to create a "Custom" element with an Action attribute with your custom action id as value like this: 如果现在要在安装项目中调用自定义动作,则只需创建一个带有Action属性的“ Custom”元素,并将您的自定义动作ID作为值,如下所示:
<Custom Action="CreateConfig" ... />
You can insert the custom action into the UI sequence or the install sequence as follows: 您可以将自定义操作插入UI序列或安装序列中,如下所示:
<!--User Interface Sequence-->
<InstallUISequence>
<Custom Action='CustomAction1' Before='ExecuteAction' />
</InstallUISequence>
<!--Installation Sequence-->
<InstallExecuteSequence>
<Custom Action='CustomAction1' After='InstallInitialize'>NOT Installed</Custom>
</InstallExecuteSequence>
You can also call a custom action from an event in a dialog box (snippet only - somewhat involved): 您还可以在对话框中的事件中调用自定义操作(仅代码段-涉及其中):
<...>
<Control Id="Next" Type="PushButton" X="236" Y="243" Width="56" Height="17" Default="yes" Text="&Next">
<Publish Event="DoAction" Value="CustomAction1">1</Publish>
<...>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.