Jason
Jason

Reputation: 259

Wix: Passing a property back from a C# custom action

Is it possible to pass a property back from a WiX custom action? I've been trying to figure out a solution for hours now, I've seen many answers but none of them work for me. Here's what I tried,

C# (Custom Action)

public class CustomActions
{
    [CustomAction]
    public static ActionResult TestAction(Session session)
    {
        session["FOO"] = "BAR";
        return ActionResult.Success;
    }
}

WiX FooDlg.wxs

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Fragment>
    <Property Id="FOO"/>
    <UI>
      <Dialog Id="FooDlg" Width="370" Height="270" Title="Foo">

        <Control Id="FOO" Type="Edit" Property="FOO" Height="17" Width="45" X="50" Y="150" Text="[FOO]" Indirect="no"/>

        <Control Id="FOO" Type="PushButton" X="150" Y="200" Width="56" Height="17" Text="Test FOO">
          <Publish Event="DoAction" Value="Testing">1</Publish>
        </Control>

      </Dialog>
    </UI>
    <CustomAction Id='FOO' BinaryKey='FooBinary' DllEntry='TestAction' Execute='immediate' Return='check'/>
    <Binary Id='FooBinary' SourceFile='FOO.dll'/>
  </Fragment>
</Wix>

Upvotes: 4

Views: 1927

Answers (2)

Hakan Yildizhan
Hakan Yildizhan

Reputation: 182

You need to specify the Id of your CustomAction in the Publish tag:

<Publish Event="DoAction" Value="FOO">1</Publish>

Upvotes: 1

Bogdan Mitrache
Bogdan Mitrache

Reputation: 10993

Yes, you can pass a property back from the custom action in the installer. Make sure the property is public (only upper case letters in its name) and that your custom action is scheduled as immediate and executes before your corespondent dialog loads (use a verbose log to track the property values during the execution of your installer, just search for the property name in it).

Upvotes: 3

Related Questions