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.
- I created the installer project
- added the exe to the application folder
- went to custom actions and added the exe to the Commit step
- InstallerClass is set to true
- 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
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
I did not call that. I've never used the Installer class before. I might be doing something very rookie here. Per your instructions, I've added the code that I have pasted below in the exe I want to run during my install. I added the exe to my application folder, then added it to the Commit custom action. Now here is the code I now have in the source of my exe that I'm trying to run:
_
Public Class ApplicationInstaller
Inherits Installer
Public Overloads Overrides Sub Commit(ByVal savedState As IDictionary)
' Do some work on commit
The_Sub_I_Have_my_codein()
MyBase.Commit(savedState)
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
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.
Best Answer
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:
Hope this helps.