AnneTheAgile
Posts: 61
Joined: Wed Jun 08, 2011 9:53 pm

WIX C# Custom Action

hi! This is from a previous post but I wanted the subject to be right.

http://www.advancedinstaller.com/forums ... =2&t=25936
Re: Vbscript for MSI use ; documentation? Wscript vs Cscript
We also recommend you to use a DLL custom action written in C# or C++, instead of VBScript and you can see some reasons why not to use VBScript .

by Dan » Fri May 17, 2013 10:37 am
Hello,
Indeed, a custom action can be executed during installation rollback. In the custom actions properties there is an "Execution Time" grupBox and one of these options is "During installation rollback".

Postby AnneTheAgile » Fri May 17, 2013 11:52 am
>"During installation rollback".
Ah, now I see, it is a radio box so I would need two actions, one for each type of thing.

I have difficulty getting the C# custom action demo to work,
http://www.advancedinstaller.com/user-g ... rp-ca.html

First, I did not see the right item to choose in the UI, so I used the Wizard.
It asked me to :
>Go to Custom Actions Page, add a “New Installed Custom Action” with sequence from Add Custom Action Tab or the toolbar and select CustomAction1.CA.dll
However,
the only Add Custom Action items are;
call function from attached native DLL
call function from installed native DLL
call function from installed DLL

So maybe that's why, but I cannot get the properties to work.

When it is immediate, of course it fails because the "dll required could not be run" - it is not installed yet.
When it is not immediate, it fails because of exception;
InstallerException: Cannot access session details from a non-immediate custom action
Dan
Posts: 4529
Joined: Wed Apr 24, 2013 3:51 pm

Re: WIX C# Custom Action

Hello,

Indeed, this tutorial of a custom action written in C# hasn't been updated for the right custom action that you should chose.

Instead of using "New Installed Custom Action" you can chose the predefined custom action: "Call function from attached native DLL".
A pop-up window will be displayed and all you have to do is to select your .dll.

If you use the "Call function from attached native DLL" custom action type, as I mentioned above, your DLL file will be embedded in the MSI package (it will not be installed on the user's machine) and you will be allowed to call your custom action at any moment of the installation.

As the exception says, a non-immediate custom action cannot access session detailes (for example: properties).
You can retrieve an installer property value from within a deferred custom action only through CustomActionData. Also, I'm afraid you cannot set an installer property from within a deferred custom action, so you should set it as immediate.

Please keep in mind that only immediate custom actions have direct access to public properties. The "Deferred", "Rollback" or "Commit" custom actions will not have access to installer properties (the properties will be empty when the custom action runs).

So can you add your custom action using a "Call function from attached native DLL" custom action scheduled as immediate and see if the behaviour persist?

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
AnneTheAgile
Posts: 61
Joined: Wed Jun 08, 2011 9:53 pm

Re: WIX C# Custom Action

Your answer was extremely helpful!

Now if I want to call my DLL function from a GUI dialog 'Next' action, can I do that? I am not getting the selection option.
thank you!
Dan
Posts: 4529
Joined: Wed Apr 24, 2013 3:51 pm

Re: WIX C# Custom Action

Hello,

In order to call a custom action from the UI dialogs your custom action should be added without sequence in the “Custom Actions” page.

In the “Dialogs” page you can go in the “Published Events” tab, on the “Next” button from the “WelcomeDlg” and you can add a new event and select from the new window which appeared “Execute custom action” event and in the “Argument” comboBox select your dll custom action.

You can also take a look on our Execute custom action on button push article.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
hadas
Posts: 43
Joined: Mon Jan 06, 2014 10:53 am

Re: WIX C# Custom Action

Hi,

I'm using C# custom action in order to update installer properties.
I have custom action located under User Selection with Execution time: Immediately. When I add message box or launchFile custom action I get that the properties aren't updated.
I've added a message box in the c# method, and the message box is presented as the last thing.

I'm using the dll action because I'm running the install on Win7 and when I'm using vbs action I get "2738 Could not access VBScript run time for custom action". Is wix custom action is the best way?

Thanks,
Hadas
Dan
Posts: 4529
Joined: Wed Apr 24, 2013 3:51 pm

Re: WIX C# Custom Action

Hello Hadas,

I'm not sure why you encountered this behavior.
The following example demonstrates how to get or set an installer public property from a C# custom action:
Setting a property

Code: Select all

session["YOUR_PROPERTY"] = "YOUR_VALUE";
Getting a property

Code: Select all

YourVariable = session["YOUR_PROPERTY"];
In order to have a better view about this, can you please send us the .AIP(project file) and a test case to support at advancedinstaller dot com so we can investigate it? If it contains confidential information you can send us a small test project which reproduce this behavior.

However, if you want to set an installer property you can use our predefined Set installer property custom action.

Please let us know if that helped, otherwise give us more details about your specific scenario.

Best regards,
Dan
Dan Ghiorghita - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube

Return to “Common Problems”