5

I'm studying Wix to build product installer. I've customized the UI successfully but be wondering how to link a custom action to control event (i.e PushButton).

I have 2 projects:

Product.Wix.CustomActions

[CustomAction]
public static ActionResult CustomAction1(Session session)
{
 session.Log("Begin CustomAction1");
 MessageBox.Show("CustomActions1");
 return ActionResult.Success;
}

Product.Wix.Setup (referenced to Product.Wix.CustomActions project). In Setup.wxs, I have declared a custom action:

<Binary Id="CustomActions" SourceFile="..\Product.Wix.CustomActions\bin\Debug\Product.Wix.CustomActions.CA.dll" />
<CustomAction Id='Action1' BinaryKey='CustomActions' DllEntry='CustomAction1' Execute='immediate' Return='check' />

I have a custom dialog with Connect button and wiring to the action as below:

<Control Id="Connect" Type="PushButton" X="325" Y="75" Width="30" Height="17" Text="...">
<Publish Event="DoAction" Value="Action1">1</Publish>
</Control>

It does not work as I expected it should pop-up a message box when clicking on the Connect button.

Cœur
  • 37,241
  • 25
  • 195
  • 267
jcha
  • 629
  • 1
  • 8
  • 16
  • 2
    I don't see what's wrong with what you are doing. Maybe there will be some helpful information in the log though. – Dave Andersen Aug 24 '11 at 16:59
  • Thank you for your suggest. The log file shows my custom action assemblies could not be loaded properly. The reason is I have unintentionally removed the section `code``code` from the config file. Added it back and everything works now. – jcha Aug 26 '11 at 04:10
  • @jcha, if you found out the reason, it's better to shape it as an answer to your own question and accept it so that others who come across this thread know exactly how it was solved – Yan Sklyarenko Aug 31 '11 at 07:30

2 Answers2

5

Am not sure whether MessageBox.Show() will work. Also its better to go with WIX dialogs as you can capture the option selected by user on the popup.

Example

<Control Id="TestConn" Type="PushButton" X="265" Y="205" Width="70" Height="18" Text="&amp;Test Connection">
    <Publish Event="DoAction" Value="Action1">1</Publish>
    <Publish Property="ERRORMSG" Value="CustomActions1">ACCEPTED = "1"</Publish>
    <Publish Event="SpawnDialog" Value="InvalidDBConnDlg">ACCEPTED = "0"</Publish>
</Control>

<Dialog Id="InvalidDBConnDlg" Width="260" Height="120" Title="[ProductName]">
    <Control Id="OK" Type="PushButton" X="102" Y="90" Width="56" Height="17" Default="yes" Cancel="yes" Text="OK" />
    <Control Id="Text" Type="Text" X="48" Y="22" Width="194" Height="60" Text="[MSGVAR]" />
    <Control Id="Icon" Type="Icon" X="15" Y="15" Width="24" Height="24" ToolTip="Information icon" FixedSize="yes" IconSize="32" Text="WixUI_Ico_Info" />
</Dialog>

Custom Action

[CustomAction]
public static ActionResult CustomAction1(Session session)
{
    session["MSGVAR"] = "Some Message";
    return ActionResult.Success;
}
Patrick Hofman
  • 153,850
  • 22
  • 249
  • 325
Sunil Agarwal
  • 4,097
  • 5
  • 44
  • 80
  • The MessageBox.Show() should work if we include System.Windows.Forms assembly. Your sample is so useful to my WIX learning. Thanks for sharing. – jcha Aug 26 '11 at 04:08
  • Thank you for your example, it helped me understand the way static text works :) Text="[MSGVAR]", I was using Text="MSGVAR" and was going crazy! – Dayan Jan 29 '13 at 05:53
2

The log file shows my custom action assemblies could not be loaded properly. The reason is I have unintentionally removed the section:

<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" />
</startup>

from the config file. Added it back and everything works now.

jcha
  • 629
  • 1
  • 8
  • 16