簡體   English   中英

如何在C#中創建自定義操作並將其綁定到Wix安裝項目上

[英]How to create custom actions in c# and bind it on a wix setup project

如何創建自定義操作並將其鏈接到我的WiX安裝項目?

我有:

  • WiX 3.11
  • 視覺工作室

您需要在解決方案中為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" />

您只需要在此處更改一些名稱:

  • CUSTOMACTIONSNAME =在引用文件夾中添加的自定義操作的名稱(默認為“ CustomActions”)
  • CUSTOMACTIONNAME =為您的自定義操作選擇一個名稱,例如“ CreateConfig”。
  • CUSTOMACTIONFUNCTION =您要調用的自定義操作項目中的函數名稱。

而已。

如果現在要在安裝項目中調用自定義動作,則只需創建一個帶有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="&amp;Next">

   <Publish Event="DoAction" Value="CustomAction1">1</Publish>

 <...>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM