nfoulon
Posts: 3
Joined: Tue Jun 10, 2008 11:28 pm

.NET Custom Action doesn't run

Hello all,

I'm evaluating AI and I wanted to try to run a simple .NET Custom Action. So I created a new C# 2008 DLL project, added the following code:

Code: Select all

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace customaction
{
    [System.ComponentModel.RunInstallerAttribute(true)]
    public class MyCustomAction : System.Configuration.Install.Installer
    {

        public MyCustomAction()
        {
           
        }

        public int LaunchDotNetCustomAction(String msg)
        {
            FileStream fs = new FileStream(Environment.GetEnvironmentVariable("TEMP") + "\\writtenByInstaller.txt", FileMode.OpenOrCreate);
            fs.Write(Encoding.Default.GetBytes(msg), 0, Encoding.Default.GetBytes(msg).Length);
            fs.Close();
            return (1);
        }


    }
}

After compiling the DLL, I added it as a .NET custom action in my "Enterprise" AI project, added the required "msg" value, built the package and when I run the Installer, the installation goes fine, the customaction.dll file is copied into the APPDIR folder, but the action is not executed, or at least doesn't produce the expected results (writing a file in the temp folder of the user).

I don't know what to do, nor where to find resources about these .NET custom actions... I know there's probably simpler ways to achieve the writing of a file, but it's only a test. I want to use the .NET actions to do much more evolved actions in the final installer.

Could you please give me some leads to follow to achieve this ?

Thanks a lot,

Best regards,

Nicolas.
Cosmin
Posts: 5797
Joined: Tue Jul 10, 2007 6:39 pm
Contact: Website

Re: .NET Custom Action doesn't run

Hi Nicolas,

Please note that LaunchDotNetCustomAction is the name of the function in our "dotNetCustAct.dll" file, it should not be a function in your custom action. This function tells Advanced Installer to use the "dotNetCustAct.dll" file to launch your .NET custom action.

Your .NET custom action must override the Install, Commit, Rollback and Uninstall methods. These overrides will tell the installer what to execute from your custom action during an Install, Commit, Rollback or Uninstall of the package. You can find a sample .NET custom action in the Install Class article in MSDN.

Note that the Install method (the override you use in your custom action) uses only one parameter: IDictionary stateSaver. This parameter contains the key/value pairs (parameters) set for your .NET custom action. Therefore, your "msg" parameter must be configured as a parameter for your custom action (in Advanced Installer) and used through the IDictionary interface (inside your custom action).

Regards,
Cosmin
Cosmin Pirvu - Advanced Installer Team
Follow us: Twitter - Facebook - YouTube
nfoulon
Posts: 3
Joined: Tue Jun 10, 2008 11:28 pm

Re: .NET Custom Action doesn't run

Thanks for your suggestion shannon, I'll try it out. I've been testing AI for a while and there are several features that disappointed me. Maybe this product will be more suited to my needs.

Nicolas.

Return to “Common Problems”