[英]How to create custom actions in c# and bind it on a wix setup project
如何創建自定義操作並將其鏈接到我的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設置項目上的References文件夾 ,然后選擇Add Reference ...。
單擊選項卡項目,然后選擇您的自定義操作項目。
對於最后一步,您需要將此代碼添加到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>
<...>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.