Question

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
Was it helpful?

Solution 3

Ok. I managed to get this working today.

I passed in CustomActionData from my WIX files

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

which I could then read in my Vb using

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

I had to ensure my CA execute was set to deferred. My above example allowed me to pass in multiple property values within one single custom action. I then also had to set the property of this CA to point to the ID of my main CA and set this to execute first.

OTHER TIPS

Have you looked at using the XMLConfig Element and the XMLFile Element which is provided by the WixUtilExtension to do the same thing you are trying to achieve? Check it out.

if you mean that you want to run this on the file that is in the same directory as the MSI file being installed, then get the [SourceDir] property into the CA, that's where the file is:

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

but it may not need to be a custom action if you are using any WiX bundle things because you could probably run it before the files get installed.

If the file belongs to Windows Installer in the sense that it is being installed by the MSI install then make sure it does not have a file hash. The file hash is in the MSI file, and if you change the file content and then the MSI installs it the hash won't match the file on disk and there will be issues. That's what msifiler is for:

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top