簡體   English   中英

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

[英]Generate text from MSI made using Wix

這聽起來可能是一個虛擬的問題,但是我想處理使用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;
        }
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM