【问题标题】:WiX - commit more than one Property to deferred Custom ActionWiX - 提交多个属性到延迟自定义操作
【发布时间】:2013-11-06 21:03:48
【问题描述】:

我的 WiX 安装程序与延迟/立即自定义操作联系时遇到问题。请原谅我的英语。

我想将用户输入的一些属性交给延迟的自定义操作。我知道我需要一个立即的自定义操作和“CustomActionData”来做到这一点。我已经以这种方式实现了它。

二进制:

<Binary Id='myAction'  SourceFile='.\TemplateGeneration.CA.dll'/>

立即自定义操作:

<CustomAction Id='Datenuebergabe' Property='DoSomething' Value='InstalllocVar=[INSTALLLOCATION]'/>

延迟的自定义操作:

<CustomAction Id='TemplateGenerationInstallKey' BinaryKey ='myAction' DllEntry='DoSomething' Impersonate='no' Execute='deferred'  Return='check' HideTarget='yes'/>

InstallExecuteSequence

 <InstallExecuteSequence>

  <Custom Action="Datenuebergabe" Sequence="1399"/>
  <Custom Action="TemplateGenerationInstallKey" Before="InstallFinalize"/>

 </InstallExecuteSequence>

在延迟的自定义操作中调用属性:

string somedata = session.CustomActionData["InstalllocVar"];
TemplateEngineCall(somedata+"templates", "install_key_cmd", somedata+"scripts", "install_key.cmd");

我的问题: 如果我尝试安装我的程序,它会中断。 使用此代码,我只能交出一项财产,但我需要提交多个财产。

有关信息: 当我查看日志文件时,在调用自定义操作时会出现 System.Collections.Generic.KeyNotFoundException。

为什么这不起作用? 好吧,我需要延迟自定义操作来写入“程序文件文件夹”。由于需要权限,因此需要延迟的自定义操作,并且在延迟之前执行的立即自定义操作应该有助于处理属性。有可能这样做吗?

我希望您了解我的问题,并且可能您可以尝试帮助我。

【问题讨论】:

    标签: wix installation custom-action wix3.6 wix-extension


    【解决方案1】:

    首先,将数据从即时自定义操作传递到延迟操作的方式存在错误。您在即时自定义操作中使用的Property 的名称必须与延迟自定义操作的Id 完全相同。在你的情况下:

    <!-- immediate CA -->
    <CustomAction Id='Datenuebergabe' Property='DoSomething' Value='InstalllocVar=[INSTALLLOCATION]'/>
    
    <!-- deferred CA -->
    <CustomAction Id='DoSomething' BinaryKey ='myAction' DllEntry='DoSomething' Impersonate='no' Execute='deferred'  Return='check' HideTarget='yes'/>
    

    这将解决 KeyNotFound 异常的问题。

    现在,回到您的问题,如何传递超过 1 个值。

    首先,在直接 CA 中使用 ; 分隔符来传递名称-值集合,如下所示:

    <CustomAction Id="SetForDoSomething" Return="check" Property="DoSomething" Value="source=[ArchiveFolder][ARCHIVENAME];target=[WebsiteFolder]"/>
    

    如您所见,我们在这里传递给延迟 CA 的 2 个名称-值对,sourcetarget。在延迟 CA 中,使用以下代码取出这些值:

    var source = session.CustomActionData["source"];
    var target = session.CustomActionData["target"];
    

    就是这样。

    【讨论】:

    • 谢谢,这是有道理的,目前看来它确实有效。但是我必须在哪个顺序调用立即自定义操作才能在安装文件后启动它?有没有办法实现它?
    • 安装文件后无法立即执行操作。这就是它被称为立即的原因 - 当 Windows Installer 代理在处理过程中到达它时立即执行它。直接 CA 旨在从系统、环境和用户收集信息,可选择对其进行验证并传递给延迟序列以供实际执行。立即 CA 绝不能更改目标系统状态。
    • 这取决于延迟操作,找不到安装模板所需的文件..嗯..
    • @YanSklyarenko 如何将值从 CustomAction 发送回 Wix
    • @asvignesh,我认为这值得一个单独的问题,因为它没有被这个问题所涵盖。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-14
    相关资源
    最近更新 更多