Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I require a MSI Custom action that copies a file from the MSI source directory

I'm creating a installer for a c# windows project using VS 2008. I'm trying to write a custom action that copies a settings file from the source directory of the MSI file stored on a file server (e.g. \server\fileshare\myappinstaller\mysetting.xml) to the target directory on the computer on which my application is been installed (e.g. C:\Program Files\My App).

The settings file can't be added in to the installer as it will contain settings with will be unique to the customer installing the app.

Does anyone have code (preferably C# or VB.NET) for such a custom action? Alternately does anyone know how to get the MSI source location (e.g. \server\fileshare\myappinstaller) within a custom action.

Many thanks

like image 458
Dean Bates Avatar asked Dec 15 '08 12:12

Dean Bates


3 Answers

I have solved this by adding

/InstallerPath="[OriginalDatabase]"

to the CustomActionData of the Custom Action (in the Tab Custom Actions of the Setup Project) and reading the value with this code in the Custom Action:

    Public Overrides Sub Commit(ByVal savedState As System.Collections.IDictionary)
        MyBase.Commit(savedState)

        Dim directoryOfMSI As String = IO.Path.GetDirectoryName(Context.Parameters("InstallerPath"))

        'Do your work here
        '...

    End Sub

Ciao! Stefan

like image 159
habakuk Avatar answered Oct 20 '22 23:10

habakuk


I would recommend you to add the XML file to the installer as one of the components to be installed. That would be the easiest way and would not require a custom action.

WiX might be an option for you. It allows you to customize XML configuration files during installation using XmlConfig.

like image 26
Dirk Vollmar Avatar answered Oct 20 '22 22:10

Dirk Vollmar


I do a similar thing, but ship a default configuration inside the MSI file and then use a MST to add the custom configuration file. It's much more reliable as everything is "native" to windows installer and I just need to send out a small custom MST to each customer.

More information on how I'm doing this can be found over at Simplest solution to replace a tiny file inside an MSI?

like image 1
saschabeaumont Avatar answered Oct 20 '22 22:10

saschabeaumont