Im writing a custom action for my WIX installer to read an XML file that contains my configuration data. This will then update a system config file.
My question is that when I run the installer it looks for my XMl file (temp.xml) in the installer files. I want this to locate this in the path that the installer is being run from so that I can change config files without having to rebuild the MSI each time.
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