Using WIX 3.7, I want to pass a connection string into a custom action. However, since the connection string contains ';' the custom action data is not being parsed correctly.
<CustomAction Id="PopulateActionPrep" Property="PopulateAction" Execute="immediate" Value="CONNECTIONSTRING="[CONNECTIONSTRING]";PRODUCTVERSION=[ProductVersion]" />
I tried using quotes to escape the connection string but that did not work. When I read the CONNECTIONSTRING property from CustomActionData it comes back with "Data Source=SqlServerName.
Is there a way to escape equal semicolons in WIX?
The answer is yes, you escape
;
using;;
:(https://github.com/wixtoolset/wix3/blob/wix311rtm/src/DTF/Libraries/WindowsInstaller/customactiondata.cs#L391-L400; see also
Unescape
andParse
right below.)Potentially even better news, you can access the data as a raw string and be in total control of how it is deserialized:
This is all that
Session.CustomActionData
is doing:https://github.com/wixtoolset/wix3/blob/wix311rtm/src/DTF/Libraries/WindowsInstaller/Session.cs#L859-L874
You don't say what language the deferred custom action is written in. Using a set property custom action is only useful for limited circumstances. What you typically do is use a code custom action for the immediate also. For example, if I was using C# DTF custom actions I'd write one custom action that creates a CustomActionData class and populate it with my dictionary. Then I'd serialize it out to the property that gets passed into the deferred custom action.
Once in the deferred custom action I create a new CustomActionData class by deserializing the CustomActionData property and then access the dictionary for my data.
By leveraging the CustomActionData class you avoid having to invent your own way of structuring and escaping the data. For a even more hard core example, see my blog where I use JSON.
Beam Me Up: Using JSON to serialize CustomActionData