views:

5608

answers:

8

I can't seem to get a custom action working. I might be doing this wrong. Here's what I'm trying to do:

I'd like to run a custom action in my application install (Visual Studio Installer project) that runs an executable. The executable simply does some system.io filecopy tasks, and I've confirmed that the executable when ran by itself works perfectly.

  1. I created the installer project
  2. added the exe to the application folder
  3. went to custom actions and added the exe to the Commit step
  4. InstallerClass is set to true
  5. Ran the installer, didn't get the result I was hoping for. So I added a line to write to the windows log. Looked in the Windows log after running the installer again and it looked like it didn't run. Added a debug.break to the exe code Unisntalled/reinstalled my installer and nothing happened. I finally sat and watched the processes and confirmed the exe never gets executed.

Any thoughts?

Targeted Systems: Windows XP, Vista Visual Studio Version: 2008 Sp1 Language: VB.NET Targeted Framework: 2.0

+6  A: 

The exe or library you are adding to the Commit step should contain a class deriving from Installer and marked with the RunInstaller attribute as follows:

[RunInstaller(true)]
public class ApplicationInstaller : Installer
{
    public override void Commit(IDictionary savedState) {
      // Do some work on commit
    }
    public override void Install(IDictionary stateSaver) {
      // Do some work on install
    }
    public override void Uninstall(IDictionary savedState) {
      // Do some work on uninstall
    }
}

Hope this helps.

Darin Dimitrov
[RunInstaller(true)] is very important.
Amitd
A: 

Excellent. I think I'm getting closer thanks to the code you posted. I converted it to VB and i'm getting this error: Cannot Find myexename.savedstate. I assume I'm supposed to pass something to the subs you posted but I don't know what. (by the way this is a console application) I added a reference to the System.Configuration.Install.dll and here is my code:


Imports System.ComponentModel
Imports System.Configuration.Install

 _
    Public Class ApplicationInstaller
        Inherits Installer
        Public Overloads Overrides Sub Commit(ByVal savedState As IDictionary)
            ' Do some work on commit
            The_Sub_I_Want_To_Run()
        End Sub
        Public Overloads Overrides Sub Install(ByVal stateSaver As IDictionary)
            ' Do some work on install
        End Sub
        Public Overloads Overrides Sub Uninstall(ByVal savedState As IDictionary)
            ' Do some work on uninstall
        End Sub
    End Class
Cj Anderson
+2  A: 

Are you calling the base method?

public override void Commit(IDictionary savedState) {
    // Do some work on commit
    base.Commit(savedState);
}
Darin Dimitrov
A: 
Cj Anderson
A: 

Hmmm... In the exe's Project Properties I clicked "Sign the assembly" and the error has gone away. However, looks like the exe doesn't run the code I want it to.

Cj Anderson
A: 

Folks if you are looking for a tutorial on how to run an executable as a Custom Action in a Windows Installer. Thanks to Darin who was helpful in the trouble shooting process.

Use this tutorial:

MSN

Cj Anderson
A: 

Set

InstallerClass
property to 'false'.

Neverrav
A: 

Thanks Cj.Anderson. I was searching to over come this problem over the net. I did all the alternative ways. Finally when i use your option(signing the assembly) my problem solved.

Thanks a ton CJ.Anderson.

Your welcome click the up arrow on my post then it will surface more often, and it might help others.
Cj Anderson