PDA

View Full Version : Custom Action from .NET



tylerman
10-26-2011, 06:59 PM
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:

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);
}
}
}

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.

Kevin.Wan
10-26-2011, 08:30 PM
Please try DotNetCoCreateObject function to load your .Net DLL.

skolte
10-27-2011, 10:11 AM
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.

9382

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.



public Cleaner ()
{
InitializeComponent();
LaunchDebuggerOnStart();
}

[Conditional("DEBUG")]
private static void LaunchDebuggerOnStart()
{
System.Diagnostics.Debugger.Launch();
}

TsungH
10-28-2011, 05:08 PM
If you have not, please refer to this thread (http://community.installshield.com/showthread.php?t=197472).