从使用Wix制作的MSI生成文本

Generate text from MSI made using Wix

本文关键字:MSI 文本 Wix      更新时间:2023-10-16

这听起来可能是一个愚蠢的问题,但我想处理使用 Wix 生成的 msi 文件的参数。我已经在VS2010中开发了Visual C++程序,例如

msiexec /i setup.exe IP="192.168.2.1" PORT="9999"

我想访问这些参数 IP 和 PORT 并将它们写入文本文件中,如下所示:

{
"IP":"192.168.2.1",
"PORT":"9999"
}

这在Wix中可能吗?如果不是,有什么办法

我相信

有一种方法可以做到这一点,尽管我自己还没有这样做。

如果将参数传递给 msiexec,如下所示:

msiexec /i setup.exe CUSTOMPROPIP="192.168.1.1" CUSTOMPROPPORT="9999"

然后,应在 msi 包随后可以分析的属性列表中设置该属性。 然后,您可以创建一个自定义操作来处理这些值,并且可以将文件写入磁盘。

<Binary Id="SetupCA" SourceFile="SetupCA.CA.dll" />
<CustomAction Id="WRITEFILETODISK" Execute="immediate" BinaryKey="SetupCA" DllEntry="WriteFileToDisk" />

请确保在安装序列中具有此自定义操作...

<InstallExecuteSequence>
  <Custom Action="WRITEFILETODISK" Sequence="2" />
  ...
</InstallExecuteSequence>

您将需要一个自定义操作项目来创建此 SetupCA.CA.dll。 自定义操作的代码如下所示:

namespace SetupCA
{
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult WriteFileToDisk(Session session)
        {
            session.Log("Begin WriteFileToDisk"); // This is useful to see when it is firing through the log file created during install with /l*vx parameter in msiexec
            // Do work here...
            string ipaddress = session["CUSTOMPROPIP"];
            string ipport = session["CUSTOMPROPPORT"];
            session.Log("Ending WriteFileToDisk");
            return ActionResult.Success;
        }
    }
}