I am modifying an existing WiX installer to handle updating an existing installation of one of our products. There are several values whose defaults are specified in properties. These properties are displayed to the user for editing and are then written to a custom configuration file by the existing installer.
My code needs to be smart enough to detect if it is doing a brand new install versus installing an older version. If it is doing a brand new install, it needs to set the properties to default values. But if it is doing an upgrade, the code needs to retrieve the valus of those properties from the existing configuration file and display those to the user.
From the reading I've done, it seems to me I need to use a type 51 custom action to set the properties. But how do I implement this custom action?
I'm thinking that I have to first define the custom action to put it in the custom action table, and then I need to stick a tag somewhere to call it. And then I need to define it.
How can I do this? What would some example code be?
You need to create a new C# Custom Action Project for WiX v3 in your solution. Change the function name to a name that fits your function. After that right click on the References Folder on your WiX setup project and choose Add Reference... . Click the tab Projects and choose your custom action Project.
After doing some more research into custom actions, I believe I've got all of this figured out. I added a <Binary> tag to the .wxs file to identify where the custom action resides. I then referenced the Binary tag's ID in the CustomAction. Finally, I added a Custom tag to the InstallExecuteSequence section that referenced the CustomAction tag by ID.
The final Custom tag mentioned above needs to go into the InstallUISequence section, not the InstallExecuteSequence section, as the custom action needs to be called before the dialog is displayed.
As for the implementation of the Custom Action itself, I added a new C# Custom Action library project to the solution. In there, I implemented a method, decorated with the [CustomAction] attribute. This method uses the values of properties stored in the Session object passed as a parameter to the method and determines the path of the current version's executable file. It then does the work needed to locate the values in the program's Configuration file that need to be preserved across versions and writes them to other properties for the upgrade script.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With