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

Ian Bell ib at ianbellsoftware.com
Fri Apr 29 08:06:45 PDT 2016


Hello Lewis,

Good catch - "The property name must match the CustomAction Id, not the DLL
entry name".    Making the change you suggested corrected the problem and I
am now able to see the property values in my custom action.    This point is
not clear in Nick Ramirez's book and he 'muddies the waters' by selecting a
custom action name which is identical to the DLL entry name.    

Cheers,

Ian

-----Original Message-----
From: Lewis Henderson [mailto:henderso at opentext.com] 
Sent: April 29, 2016 08:45
To: ib at ianbellsoftware.com; WiX Toolset Users Mailing List
Subject: RE: [wix-users] how to pass multiple arguments to C# custom action

Hi Ian,

The property name must match the CustomAction Id, not the DLL entry name.
So, your property should be named " CustomActionId_MyCustomAction ".  Try
that out and see if it solves your issue.

				Lewis Henderson
				OpenText, Inc.

-----Original Message-----
From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf Of
Ian Bell
Sent: Friday, April 29, 2016 1:07 AM
To: 'WiX Toolset Users Mailing List' <wix-users at lists.wixtoolset.org>
Subject: [wix-users] how to pass multiple arguments to C# custom action

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



____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant
http://www.firegiant.com/




More information about the wix-users mailing list