We help IT Professionals succeed at work.

Deployment Custom Action

I have created a Windows Set-up and Deployment Package for an application. Each User will require a database file with different contents specific to them to be installed. So instead of re-building the install package every time I want to just place the unique database file on to the installation cd and have it automatically copied to the users chosen installation locaton.

 I know I am supposed to create a custom installer class to include with the package, but how do you know what target path the user has chosen for the installation i.e. Is it a property that is available when coding the custom install class?  Anyone have an example e.g. Copy app.path\data.mdb        targetpath\data.mdb    
Watch Question

Yes, you can access any property of the installer from within your custom action class.  

There's a Microsoft help article titled "Walkthrough: Using a Custom Action to Display a Message at Installation" that explains how to create the custom installer class and how to create (and access) custom properties, but it does not explain about the built-in properties available from the installer.  To find those constants, you have to find the article titled "Property Reference" (with the setup project open, just press F1, then enter "Property Reference" in the search window to see the complete list of properties.

Here's the skinny:

(1) In your custom installer class, you need to define an Install method.  This is where you code your custom actions.  This class has access to any properties that you pass to it.  In the example below, I used the SourceDir and UserName properties.  I'll explain how to pass these variables to your custom class in the next step.

(2) After you've added the primary output from your custom action class (a dll file) to the Install custom action, select the "Primary output from ..." line then select the CustomActionData property (see image).  This is where you pass the properties to your class.  In my example, I used SourceDir and UserName, so my CustomActionData property looks like this:

/SourceDir="[SourceDir]\" /UserName="[USERNAME]"

That's it.  You can access any built-in windows installer property or any property that you defined in any dialog.
    Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
        Dim SourceDir As String = Me.Context.Parameters.Item("SourceDir")
        Dim UserName As String = Me.Context.Parameters.Item("UserName")
        If SourceDir Is Nothing Then SourceDir = "SourceDir ERROR"
        If UserName Is Nothing Then UserName = "UserName ERROR"
        MsgBox(SourceDir, MsgBoxStyle.OkOnly, UserName)
    End Sub

Open in new window



Many thanks Bill, I had almost got there but I had'nt quite got the syntax for passing 2 parameters e.g. source and target, I had in error a ';' between the two just for luck!

Now all works fine.  I have also put my dll primary output unnder the Commit node as i wanted to make sure everything else was installed/folders set-up first.



Explore More ContentExplore courses, solutions, and other research materials related to this topic.