爲我的WIX安裝程序編寫自定義操作來讀取包含我的配置數據的XML文件。這會更新一個系統配置文件。CustomAction DLL Wix讀取XML VB 2012
我的問題是,當我運行安裝程序時,它會在安裝程序文件中查找我的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
完全同意應該用於XML寫入,但不支持XML讀取。 –