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

KONDURU Pavan Pavan.KONDURU at 3ds.com
Fri Apr 29 09:41:47 PDT 2016


Hi Ian,

This is how I pass multiple variables to my CAs, hope this helps. It's pretty simple:

In my product.wxs

<CustomAction Id="SetPropertyMyserver" Property="UpdateMyProps" Value="[INSTALLLOCATION],[DISCO_HOSTNAME],[CONFIG_SERVERPORT]" Execute="immediate"/>
<CustomAction Id="UpdateMyProps" BinaryKey="CustomAction" DllEntry="UpdateDiscoProps" Return="check" Execute='deferred' Impersonate='no'/>

<Custom Action="SetPropertyMyserver"      Before="UpdateMyProps"></ Custom>
      <Custom Action="UpdateMyProps"      After="someCA"></Custom>

In my CA code:

String customData = session["CustomActionData"];

            Record record = new Record(1);

            string[] valueArg = customData.Split(',');
            string location = valueArg[0];
            string hostname = valueArg[1];
            string port = valueArg[2];


--Pavan
-----Original Message-----
From: wix-users [mailto:wix-users-bounces at lists.wixtoolset.org] On Behalf Of Ian Bell
Sent: Thursday, April 28, 2016 10:07 PM
To: 'WiX Toolset Users Mailing List'
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/
This email and any attachments are intended solely for the use of the individual or entity to whom it is addressed and may be confidential and/or privileged.

If you are not one of the named recipients or have received this email in error,

(i) you should not read, disclose, or copy it,

(ii) please notify sender of your receipt by reply email and delete this email and all attachments,

(iii) Dassault Systemes does not accept or assume any liability or responsibility for any use of or reliance on this email.

For other languages, go to http://www.3ds.com/terms/email-disclaimer


More information about the wix-users mailing list