I am working on a rather large size wix v3 installer. I am required to add registry entries based on various conditions. For that, I will have to write elaborate logic in the C# side. I will do that in custom action. To test my framework, I created a simple custom action and am trying to just test passing parameters from the wxs file to the custom action (C#) side. No matter what I do, when I check the arguments on the custom action side, the arguments are just not there. The related part of the wxs file and the custom action (C#) are shown below. Any insight/help is greatly appreciated.
product.wxs file:
<Binary Id="CustomActionBinary" SourceFile="$(var.RegistryManagementCustomActions.TargetDir)$(var.RegistryManagementCustomActions.TargetName).CA.dll" />
<CustomAction Id="CustomActionAddRegistryEntries" Impersonate="no" BinaryKey="CustomActionBinary" DllEntry="AddRegistryEntries" Execute="deferred" Return="check" />
<CustomAction Id="CustomActionAddRegistryEntriesProperty" Property="CustomActionAddRegistryEntries"
Value="Arg1=1;Arg2=2;Arg3=3;INSTDIR=[INSTALLFOLDER]" />
<!--Installation Sequence-->
<InstallExecuteSequence>
<!--add registry entries upon install-->
<Custom Action='CustomActionAddRegistryEntries' After='InstallInitialize'>NOT Installed</Custom>
<!--remove registry entries upon uninstall-->
<Custom Action='CustomActionRemoveRegistryEntries' After='InstallFinalize'>
(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
</Custom>
</InstallExecuteSequence>
Custom Action (C#) file:
[CustomAction]
public static ActionResult AddRegistryEntries(Session session)
{
CustomActionData data = session.CustomActionData;
string ss = data.Count.ToString() + "\n";
foreach (var k in data)
{
ss += k.Key + ";" + k.Value + "\n";
}
//Access arguments
//string arg1 = session.Format(data["Arg1"]);
session.Log("Begin adding registry entries");
string s = "Running AddRegistryEntries";
s += "\n" + ss;
File.WriteAllText(@"C:\Users\Bhairav\Desktop\customactiontest.txt", s);
return ActionResult.Success;
}
FIX: In the product.wix file (Towards the end of body): Fix: In the tag, towards the end:
<Binary Id="CustomActionBinary" SourceFile="$(var.RegistryManagementCustomActions.TargetDir)$(var.RegistryManagementCustomActions.TargetName).CA.dll" />
<CustomAction Id="CustomActionAddRegistryEntries" Impersonate="no" BinaryKey="CustomActionBinary" DllEntry="AddRegistryEntries" Execute="deferred" Return="check" />
<CustomAction Id="CustomActionAddRegistryEntriesProperty" Property="CustomActionAddRegistryEntries"
Value="InstallDir=[INSTALLFOLDER]" />
<CustomAction Id="CustomActionRemoveRegistryEntries" Impersonate="no" BinaryKey="CustomActionBinary" DllEntry="RemoveRegistryEntries" Return="check" />
<!--Installation Sequence-->
<InstallExecuteSequence>
<!--add registry entries upon install-->
<Custom Action="CustomActionAddRegistryEntriesProperty" After="CostFinalize" />
<Custom Action='CustomActionAddRegistryEntries' After='InstallInitialize'>NOT Installed</Custom>
<!--remove registry entries upon uninstall-->
<Custom Action='CustomActionRemoveRegistryEntries' After='InstallFinalize'>
(NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
</Custom>
</InstallExecuteSequence>
In the custom action (C#) side:
[CustomAction]
public static ActionResult AddRegistryEntries(Session session)
{
CustomActionData data = session.CustomActionData;
string installDir = data["InstallDir"];
session.Log("Begin adding registry entries");
session.Log("InstallDir = " + installDir);
return ActionResult.Success;
}
I hope this helps someone save some trouble.