【发布时间】:2014-04-17 08:21:43
【问题描述】:
我正在为我的 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
【问题讨论】: