要创建MSI,我使用Gradle插件SetupBuilder

安装后,我需要从安装目录执行二进制文件。但是我无法访问INSTALLDIR属性:

msi {
  postinst = '''
MsgBox ("INSTALLDIR: " & Session.Property("INSTALLDIR"))
'''
}

但:

gradle - WiX/SetupBuilder在vbscript中获取INSTALLDIR的值-LMLPHP

我发现SetupBuilder在.wxs文件中创建了以下自定义操作:
    <CustomAction Execute="deferred" Id="Postinst_Script0" Impersonate="no" Script="vbscript">
MsgBox ("INSTALLDIR: " &amp; Session.Property("INSTALLDIR"))
</CustomAction>

<CustomAction Id="SetPropertiesPostinst_Script0" Property="Postinst_Script0" Value="INSTALLDIR='[INSTALLDIR]';ProductCode='[ProductCode]';INSTANCE_ID='[INSTANCE_ID]'"/>

他们被这样称呼:
<InstallExecuteSequence>
  <Custom Action="Postinst_Script0" Before="InstallFinalize">NOT Installed OR REINSTALL OR UPGRADINGPRODUCTCODE</Custom>
  <Custom Action="SetPropertiesPostinst_Script0" Before="Postinst_Script0"/>
</InstallExecuteSequence>

根据CustomAction Element上的WiX文档,PropertyValue的组合应该会导致Custom Action Type 51,这几乎让我迷路了。仅用于访问简单属性的未知事物太多了。

有人可以帮我理解吗?我如何进入酒店?

最佳答案

你可以试试:

MsgBox ("CustomActionData: " & Session.Property("CustomActionData"))

如果这项工作可以尝试:
Dim properties
loadCustomActionData properties
MsgBox ("INSTALLDIR: " & properties("INSTALLDIR"))

' =====================
' Decode the CustomActionData
' =====================
Sub loadCustomActionData( ByRef properties )
    Dim data, regexp, matches, token
    data = Session.Property("CustomActionData")

    Set regexp = new RegExp
    regexp.Global = true
    regexp.Pattern = "((.*?)='(.*?)'(;|$))"

    Set properties = CreateObject( "Scripting.Dictionary" )
    Set matches = regexp.Execute( data )
    For Each token In matches
        properties.Add token.Submatches(1), token.Submatches(2)
    Next
End Sub

08-27 00:02