如何获取 wix 属性 值到 wix vb 自定义操作项目?

how to get wix propery value to wix vb custom action project?

我为这个 &%^&@#$ 问题苦苦挣扎了两个多星期,但它仍然无法正常工作。我需要用户输入一些数据,这些数据需要发送到我的 WIX VB 自定义操作项目。但是它永远不会达到它。我目前在 WIX 中有以下代码:

用户输入:

 <Control Id="InputField" Type="Edit" X="20" Y="100" Width="140" Height="18" Property="ValueAdaptionScript" Text="{40}"/>

正在将 DLL 添加到安装程序:

    <ComponentGroup Id ="DLL" Directory ="INSTALLFOLDER">
  <Component Id ="StringTransfer" Guid ="{479947FA-C324-411C-9B98-083E79C116CB}">
    <File Id ="StringTransfer" KeyPath="yes" Source="C:\Users\fjansen\Documents\Visual Studio 2015\Projects\String Transfer\Data Transfer\obj\x86\Debug\DataTransfer.CA.dll" />
  </Component>
</ComponentGroup>

指向 DLL 的自定义操作和二进制文件:

    <Binary Id="StringTransfer" SourceFile="C:\Users\fjansen\Documents\Visual Studio 2015\Projects\String Transfer\Data Transfer\obj\x86\Debug\DataTransfer.CA.dll" />

  <CustomAction
      Id="SetProperties"
      Property="ValueAdaptionScript"
      HideTarget="no"
      Value="[MachineIdNumber]"
    />

  <CustomAction
      Id="ValueAdaptionScript"
      BinaryKey="StringTransfer"
      DllEntry="CustomAction1"
      Execute="deferred"
      Impersonate="no"
      Return="check"
    />

  <InstallExecuteSequence>
    <Custom Action="SetProperties" Before="ValueAdaptionScript" />
    <Custom Action="ValueAdaptionScript" Before="InstallFinalize">NOT REMOVE="ALL"</Custom>
  </InstallExecuteSequence>

在 WIX 自定义操作项目中,我创建了一个写入文件的函数,因此我可以查看从 WIX 收到的内容。这只是为了测试值的传递,如果值的传递有效,我会调整代码,让它用 .INI 文件中用户的输入替换特定的文本。

WIX自定义动作项目代码:

Imports System.IO
Imports System.Reflection

Public Class CustomActions
    Public Shared Property MachineIdNumber As String
    Public Shared Property ValueAdaptionScript As String

    <CustomAction()>
    Public Shared Function CustomAction1(ByVal session As Session) As ActionResult
        Dim file As System.IO.StreamWriter
        file = My.Computer.FileSystem.OpenTextFileWriter("c:\test.txt", True)
        file.WriteLine("test")
        file.WriteLine(MachineIdNumber)
        file.WriteLine(ValueAdaptionScript)
        file.WriteLine(CustomAction1)
        file.Close()

        Return ActionResult.Success
    End Function

End Class

当安装程序 运行 使用所有这些代码时,我确实得到了一个包含以下内容的文本文件:文本和 0。第一个是合乎逻辑的,因为我对其进行了硬编码,而 0 是 CustomAction1 的产物并且意味着 CustomAction 已成功结束。一切都很好,但我没有得到我想看到的价值。

我真的需要这方面的帮助,因为我只是没有让它工作并且在这个问题上花了很多时间。萌芽,主要是因为这是我能够部署安装程序之前的最后一个障碍。

提前致谢,

F.J

这里有一些不正确的地方。

  1. 在 UI 序列和执行序列之间传递的属性需要全部大写 - 这意味着它们是 public。它们也应该首先使用 Secure='yes' 声明。

  2. 您无需在自定义操作代码中声明属性,而是从安装过程中获取它们。如果你的 CA 是即时的,你会说类似 varname = session["VALIDATIONSCRIPT"] 但它被推迟了,所以这是一个很好的概述:

http://vadmyst.blogspot.com/2006/05/deferred-custom-actions-with-wix.html

并设置了延迟 CA 属性,您将使用 varname = session["CustomActionData"]

还有这个:

https://www.firegiant.com/wix/tutorial/events-and-actions/at-a-later-stage/