【问题标题】:Generate text from MSI made using Wix从使用 Wix 制作的 MSI 生成文本
【发布时间】:2014-11-19 09:50:49
【问题描述】:

这听起来可能是一个愚蠢的问题,但我想处理使用 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 中可行吗?如果不是,有什么办法。

【问题讨论】:

    标签: c++ visual-studio-2010 visual-c++ wix


    【解决方案1】:

    我相信有办法做到这一点,虽然我自己没有这样做。

    如果您将参数传递给 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;
            }
        }
    }
    

    【讨论】:

    • 我将尝试此代码并让您知道它是否有效。他们顺便说一句
    猜你喜欢
    • 2014-11-16
    • 2010-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多