cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
tylerman
Level 2

Custom Action from .NET

Hi Guys,

I'm new to InstallShield, but relatively experienced with .NET. I'm trying to build a custom action from a .NET DLL. Here is the code from my .NET DLL:

[FONT="Courier New"]using System.Linq;
using System.Text;
using System.IO;
using System.Configuration.Install;
using System.ComponentModel;

namespace KnowledgePartners.Trim.Installer
{
[RunInstaller(true)]
public class Cleaner : System.Configuration.Install.Installer
{
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Install(IDictionary stateSaver)
{
try
{
base.Install(stateSaver);
StreamWriter sw = new StreamWriter("C:\\DoesMyCustomActionWork.txt");
sw.WriteLine("yes");
sw.Close();
return;

}
catch (System.Exception ex)
{
}

}


[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Uninstall(IDictionary savedState)
{
try
{
base.Uninstall(savedState);
File.Delete("C:\\DoesMyCustomActionWork.txt");

}
catch (System.Exception ex)
{
}

}


[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Commit(IDictionary savedState)
{
base.Commit(savedState);

}


[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
public override void Rollback(IDictionary savedState)
{
base.Rollback(savedState);

}

}

}[/FONT]

As you can see its relatively straightforward. However when I add this DLL as a .NET custom action in InstallShield and Debug, I get the message:
Can not find the entry point of function 'KnowledgePartners.Trim.Installer.Cleaner.Install', make sure it is exported.

I'm not exactly sure what I've done wrong.. and I may ofcourse be completely off track. I can't seem to find anything that walks through how to do this, so if anyone knows, or has a link to an explanation it would be greatly appreciated.

Cheers.
Labels (1)
0 Kudos
(3) Replies
Not applicable

Please try DotNetCoCreateObject function to load your .Net DLL.
0 Kudos
skolte
Level 7

I won't add this DLL directly as a custom action.

Instead add it to a component (without using Dynamic Links) and in component's properties select .NET Installer Class to Yes. It will also let you select this assembly under .NET Application File. That should do it.



Also, with Installer Classes my experience is it is difficult to debug the code in case of problems. The easier solution is to add a conditional "debugger launch" so that you can attach your Visual Studio debugger in case you want to debug your code.

[CODE]
public Cleaner ()
{
InitializeComponent();
LaunchDebuggerOnStart();
}

[Conditional("DEBUG")]
private static void LaunchDebuggerOnStart()
{
System.Diagnostics.Debugger.Launch();
}[/CODE]
0 Kudos
TsungH
Level 12

If you have not, please refer to this thread.
0 Kudos