cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
blood_on_ice
Level 4

Calling C# Dll CustomAction

Hello,

I'm new to InstallShield, i'm wondering, how I could call my Installer-C#-DLL. I've previously used the VisualStudio Setup project to build my msi-file. I've used an Installer-DLL written in C# to do things during the installation, uninstall etc:

[FONT="Courier New"][SIZE="1"]using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using Microsoft.Build.Tasks.Deployment.ManifestUtilities;
using System.Security.Cryptography.X509Certificates;

namespace CustomActions
{
[RunInstaller(true)]
public partial class Installer1 : Installer
{
public Installer1()
{
InitializeComponent();
}

protected override void OnAfterInstall(System.Collections.IDictionary savedState)
{
base.OnAfterInstall(savedState);
setDeploymentUrlAndSign(Context.Parameters["CertFilePath"], Context.Parameters["CertPassword"],
Context.Parameters["NewDeploymentUrl"], Context.Parameters["deploymentManifestPath"]);

resignApplicationManifest(Context.Parameters["CertFilePath"], Context.Parameters["CertPassword"],
Context.Parameters["ApplicationManifestPath"], Context.Parameters["AppDir"]);
}

public override void Commit(System.Collections.IDictionary savedState)
{
base.Commit(savedState);
}

public override void Install(System.Collections.IDictionary stateSaver)
{
base.Install(stateSaver);
stateSaver.Add("CertFilePath", Context.Parameters["CertFilePath"].ToString());
stateSaver.Add("CertPassword", Context.Parameters["CertPassword"].ToString());
stateSaver.Add("NewDeploymentUrl", Context.Parameters["NewDeploymentUrl"].ToString());
stateSaver.Add("deploymentManifestPath", Context.Parameters["deploymentManifestPath"].ToString());
stateSaver.Add("ApplicationManifestPath", Context.Parameters["ApplicationManifestPath"].ToString());
stateSaver.Add("AppDir", Context.Parameters["AppDir"].ToString());
}

private void setDeploymentUrlAndSign(string certFilePath, string certPassword,
string newDeploymentUrl, string deploymentManifestPath)
{
string newDeploymentManifest = deploymentManifestPath + "_temp";

// Open the deployment file (.application)
DeployManifest deployManifest = ManifestReader.ReadManifest(deploymentManifestPath, false) as DeployManifest;

// Set the URL to the new url:
deployManifest.DeploymentUrl = newDeploymentUrl;

// Create a new manifest file (in a temp folder)
ManifestWriter.WriteManifest(deployManifest, newDeploymentManifest);

// Make sure the entered cert file exists
if (File.Exists(certFilePath))
{
// Construct cert object for cert
X509Certificate2 cert;
if (string.IsNullOrEmpty(certPassword))
{
cert = new X509Certificate2(certFilePath);
}
else
{
cert = new X509Certificate2(certFilePath, certPassword);
}

SecurityUtilities.SignFile(cert, null, newDeploymentManifest);
Console.WriteLine("Signed! new file: " + newDeploymentManifest);
}
}

private void resignApplicationManifest(string certFilePath, string certPassword,
string applicationManifestPath, string appDir)
{
string newApplicationManifest = applicationManifestPath + "_temp";
string[] appDirs = Directory.GetDirectories(appDir);
ApplicationManifest appManifest = ManifestReader.ReadManifest(applicationManifestPath, false) as ApplicationManifest;
appManifest.ResolveFiles(appDirs);
appManifest.UpdateFileInfo();
ManifestWriter.WriteManifest(appManifest, newApplicationManifest);
X509Certificate2 cert = new X509Certificate2(certFilePath, certPassword);

// Make sure the entered cert file exists
if (File.Exists(certFilePath))
{
// Construct cert object for cert
X509Certificate2 cert1;
if (string.IsNullOrEmpty(certPassword))
{
cert1 = new X509Certificate2(certFilePath);
}
else
{
cert1 = new X509Certificate2(certFilePath, certPassword);
}

SecurityUtilities.SignFile(cert1, null, newApplicationManifest);
Console.WriteLine("Signed! new file: " + newApplicationManifest);
}
}
}
}[/SIZE][/FONT]

Can I use this DLL in my Install-Shield project (*.ism File)? Or how can I use my C# Code in Install-Shield? How can I call an C# DLL or how should my DLL looks like for being called in Install-Shield and how can I call it?

Thanks for an answer:)

Kind regards,
Peter
Labels (1)
0 Kudos
(5) Replies
nikhilgupta
Level 5

Create a component for the DLL, mark the dll as key file and then in the components properties set Installer class to Yes.
0 Kudos
blood_on_ice
Level 4

Thanks for the quick answer...hm could you explain that a bit more, how can I create a component for a dll and mark the dll? Also I can't find the properties, where I can set Installer Class to YES...

Kind regards,
Peter

nikhilgupta wrote:
Create a component for the DLL, mark the dll as key file and then in the components properties set Installer class to Yes.
0 Kudos
blood_on_ice
Level 4

nikhilgupta wrote:
Create a component for the DLL, mark the dll as key file and then in the components properties set Installer class to Yes.


So finally i got it:
http://community.macrovision.com/showthread.php?t=168533&highlight=CoCreateObjectDotNet

kind regards,
Peter
0 Kudos
devender
Level 2

I too trying to call C# custom action using installshield. We are using installshield 2009 Premier edition.
In my C# code, I am using the below function.

protected override void OnBeforeInstall(System.Collections.IDictionary savedState)
{
base.OnBeforeInstall(savedState);
--
}
public override void Install(System.Collections.IDictionary stateSaver)
{
}
Similarly calling commit, Uninstall,rollback Method.

I have a doubt, what to give in the Target field when we run the Custom action Wizard?
This custom action dll has other dependend dlls too. It seems http://community.macrovision.com/ link is no longer available.
Is there any other link which explains, how to call the C# custom action?
Really appreciate any help in this regard, if you have worked on similar requirement.

Regards
Devender
0 Kudos
devender
Level 2

I too was trying to call C# custom action using installshield. We are using installshield 2009 Premier edition.
In my C# code, I am using the below function.

protected override void OnBeforeInstall(System.Collections.IDictionary savedState)
{
base.OnBeforeInstall(savedState);
--
}
public override void Install(System.Collections.IDictionary stateSaver)
{
}
Similarly calling commit, Uninstall,rollback Method.

I have a doubt, what to give in the Target field when we run the Custom action Wizard?
This custom action dll has other dependend dlls too. It seems http://community.macrovision.com/ link
is no longer available.
Is there any other link which explains, how to call the C# custom action?
Really appreciate any help in this regard, if you have worked on similar requirement.
0 Kudos