簡體   English   中英

CustomAction DLL Wix讀取XML VB 2012

[英]CustomAction DLL Wix read XML VB 2012

我為WIX安裝程序編寫了一個自定義操作,以讀取包含我的配置數據的XML文件。 然后,這將更新系統配置文件。

我的問題是,當我運行安裝程序時,它將在安裝程序文件中查找我的XMl文件(temp.xml)。 我希望它可以在運行安裝程序的路徑中找到它,以便我可以更改配置文件,而不必每次都重新構建MSI。

Public Shared Function CustomAction1(ByVal session As Session) As ActionResult
        session.Log("Begin CustomAction1")

        Dim installDir = Environment.GetEnvironmentVariable("EnactorInstall")

        Dim doc As XmlDocument = New XmlDocument()
        doc.Load("\Test.xml")
        Dim root As XmlNode = doc.DocumentElement
        Dim nodePorts As XmlNode = root.SelectSingleNode("/config/ports")
        Dim BO As String = nodePorts.Attributes.ItemOf("BO").InnerText
        Dim BP As String = nodePorts.Attributes.ItemOf("BP").InnerText
        Dim EM As String = nodePorts.Attributes.ItemOf("EM").InnerText
        Dim WS As String = nodePorts.Attributes.ItemOf("WS").InnerText

        REM Modify enactor.Xml
        Dim enactorXML = installDir & "config\ProcessingServer\enactor.xml"
        Using file As New FileStream(enactorXML, FileMode.Open, FileAccess.ReadWrite)
            REM read the file to memory
            Dim reader As New StreamReader(file)
            Dim content As String = reader.ReadToEnd()

            REM replace tokens
            content = Replace(content, "{ENVIRONMENT}", BO)
            content = Replace(content, "{DEVICE_TYPE}", EM)
            content = Replace(content, "{DEVICE_ID}", WS)
            content = Replace(content, "{LOCATION_ID}", BP)
            content = Replace(content, "{APPLICATION_HOME}", BO)
            content = Replace(content, "{TRANSACTION_NUMBER}", EM)
            content = Replace(content, "{SESSIONS}", EM)
            content = Replace(content, "{RATE_BOARD_PORT}", BO)

            REM clear the file
            file.SetLength(0)

            REM write back to the file
            Dim writer As New StreamWriter(file)
            writer.Write(content)
            writer.Flush()
            writer.Close()
        End Using

        Return ActionResult.Success
    End Function

您是否看過使用WixUtilExtension提供的XMLConfig元素XMLFile元素來完成您要實現的目標? 看看這個。

如果您要在與要安裝的MSI文件位於同一目錄中的文件上運行此文件,則將[SourceDir]屬性放入CA,該文件位於:

http://msdn.microsoft.com/zh-CN/library/aa371857(v=vs.85).aspx

但是,如果您使用的是任何WiX捆綁包產品,則可能無需執行自定義操作,因為您可能可以在安裝文件之前運行它。

如果該文件屬於MSI安裝正在安裝的Windows Installer,則請確保該文件沒有文件哈希。 文件哈希位於MSI文件中,如果更改文件內容然后由MSI安裝,則哈希將與磁盤上的文件不匹配,並且會出現問題。 這就是msifiler的用途:

http://msdn.microsoft.com/zh-CN/library/aa370108(v=vs.85).aspx

好。 我今天設法解決了這個問題。

我從WIX文件中傳入了CustomActionData

<CustomAction Id="SetPathInst" Property="EnactorInstaller" Value="DataKey=[SourceDir];DataKeyInst=[INSTALLDIR]" />

然后我可以使用Vb讀取

   Dim srcPath As String = session.CustomActionData("DataKey")
   Dim srcPathInst As String = session.CustomActionData("DataKeyInst")

我必須確保將CA執行設置為推遲。 我上面的示例允許我在一個自定義操作中傳遞多個屬性值。 然后,我還必須將該CA的屬性設置為指向我的主CA的ID,並將其設置為首先執行。

暫無
暫無

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

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