小编典典

如何将参数传递给自定义操作?

c#

我正在尝试使用“值”属性创建自定义操作,我想将参数传递给C#代码(TARGETDIR和版本)。

但是,我收到一条错误消息,指出DLLENtry和Value无法共存。但是没有dllentry的自定义操作无效。

这是代码:

 <CustomAction Id="SetMAWPrefferences"
                Value="InstallDir=[TARGETDIR];Version=2.0.0.1"
                Return="check"
                Execute="commit"
                BinaryKey="ImportExportBinary"                    
                />

为此,我得到了这个错误:

错误9 ICE68:动作’SetMAWPrefferences’的自定义动作类型无效。

有什么想法怎么做?


阅读 502

收藏
2020-05-19

共1个答案

小编典典

注意,您Value以错误的方式使用属性:

…此属性必须与Property属性一起使用才能设置属性…
Source


基于在C#中创建WiX自定义操作和传递参数一文,您应该:

  1. 创建具有所需值的属性:

    <Property Id="InstallDir" Value="someDefaultValue" />
    

  2. 创建自定义操作以设置InstallDir属性:

    <CustomAction Id="SetDirProp" Property="InstallDir" Value="[TARGETDIR]" />
    
  3. 创建自定义操作:

    <CustomAction Id="SetMAWPrefferences" 
    Return="check" 
    Execute="commit" 
    BinaryKey="ImportExportBinary" 
    DllEntry="YourCustomAction" />
    
  4. 计划自定义操作以在安装过程中执行:

    <InstallExecuteSequence>
    <Custom Action="SetDirProp" After="CostFinalize" />
    <Custom Action="SetMAWPreferences" ... />
    ...
    

  5. 通过以下自定义操作访问这些属性:

    [CustomAction]
    

    public static ActionResult YourCustomAction(Session session)
    {
    // session[“InstallDir”]
    // session[“Version”]
    }

2020-05-19