Search code examples
c#visual-studio-2010setup-deployment

How to add some code to c# Installer


I have made an installer which contains the exe and dlls, made in using Visual studio the thing is can i add some code to it?

example when it install i just want to run 3-4 lines of code.

1- Get mac address add to database, with a unique key.

And similarly on uninstall remove the mac address from the database .

Is this possible in this current scenario using the default setup project?


Solution

  • You will need to use a CustomAction for your installer. With this you can run a program, script, write a registry key, or whatever. Here's a simple example using a custom installer class to show a message during the installation (in VB.NET but easily translatable):

    Public Overrides Sub Install(ByVal stateSaver As System.Collections.IDictionary)
      MyBase.Install(stateSaver)
      Dim myInput As String = Me.Context.Parameters.Item("Message")
      If myInput Is Nothing Then
        myInput = "There was no message specified"
      End If
      MsgBox(myInput)
    End Sub
    

    You would need to follow the steps in the link to fully reproduce the sample.