[wix-users] how to pass multiple arguments to C# custom action

Ian Bell ib at ianbellsoftware.com
Thu Apr 28 22:07:08 PDT 2016


I am following an example in Nick Ramirez's book Wix 3.6 on how to pass
multiple arguments to a C# custom action.   I can successfully pass a single
argument but not multiple argument.    The end of log file shows
'myDeferredCA' property is correctly defined but
'session.CustomActionData.Values'  is always empty in my custom action.   I
am obviously missing something simple and am hoping someone here can spot my
'hiccup'.   The 'session.CustomActionData.Values' should appear between the
log entries 'Begin myDeferredCA' and 'End myDeferredCA' but the values
'abc123', 'def567' and 'ghi890' never appear between these two log entries.
Can anyone spot what I am doing wrong?

ThanX in advance.

Ian





CustomAction.cs
======================================================================
namespace CustomAction1
{
	public class CustomActions
	{
		[CustomAction]
		public static ActionResult myDeferredCA( Session session )
		{
			//Debugger.Launch();
			session.Log( "Begin myDeferredCA" );

			ICollection<string> values =
session.CustomActionData.Values;
			foreach( var value in values ) {
				session.Log( "value = {0}", value );
			}

			session.Log( "End myDeferredCA" );
			return ActionResult.Success;
		}
	}
}



Product.wxs
======================================================================
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">

  <Product Id="*" Name="_MySetupProject" Language="1033" Version="1.0.0.0"
Manufacturer="MyCompany" UpgradeCode="b0d199cd-d214-4e68-95c0-ecf3aa2d0b0d">
    <Package InstallerVersion="200" Compressed="yes"
InstallScope="perMachine" />
    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is
already installed." />
    <MediaTemplate EmbedCab="yes"/>

    <Property Id="PROP1" Value="abc123" />
    <Property Id="PROP2" Value="def567" />
    <Property Id="PROP3" Value="ghi890" />
    <CustomAction Id="CustomActionId_SetProperties"
                  Property="myDeferredCA"
                  Value="Prop1=[PROP1];Prop2=[PROP2];Prop3=[PROP3]" />
    
    <Binary Id="BinaryId_MyCustomActionsDLL"
 
SourceFile="$(var.CustomAction1.TargetDir)$(var.CustomAction1.TargetName).ca
.dll" />
    <CustomAction Id="CustomActionId_MyCustomAction"
                  BinaryKey="BinaryId_MyCustomActionsDLL"
                  DllEntry="myDeferredCA"
                  Execute="deferred"
                  Return="check"/>
    
    <InstallExecuteSequence>
      <Custom Action="CustomActionId_SetProperties"
Before="CustomActionId_MyCustomAction" />
      <Custom Action="CustomActionId_MyCustomAction"
After="InstallInitialize" />
    </InstallExecuteSequence>

    <Feature Id="ProductFeature" Title="My Setup Project 01" Level="1">
      <ComponentGroupRef Id="ComponentGroupId_ProgramFilesFolder" />
    </Feature>
  </Product>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="DirectoryId_ProgramFilesFolder" Name="MyCompany" />
      </Directory>
    </Directory>
  </Fragment>

  <Fragment>
    <ComponentGroup Id="ComponentGroupId_ProgramFilesFolder"
Directory="DirectoryId_ProgramFilesFolder">
      <Component Id="ComponentId_MyApplication" Guid="*" >
        <File Id="FileId_MyApplication"
Source="$(var.MyApplication.TargetPath)" />
      </Component>
    </ComponentGroup>
  </Fragment>

</Wix>



MySetuProject.log
======================================================================
Calling custom action CustomAction1!CustomAction1.CustomActions.myDeferredCA
Begin myDeferredCA
End myDeferredCA
MSI (s) (F0:90) [00:57:42:380]: Executing op:
ActionStart(Name=ProcessComponents,Description=Updating component




More information about the wix-users mailing list