confusedMind
confusedMind

Reputation: 2653

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?

Upvotes: 1

Views: 2823

Answers (2)

jglouie
jglouie

Reputation: 12880

You could use the .NET installer classes and wire those up from the default setup project. You override some methods and then they get called at install/uninstall time. Here's a tutorial on how to do this.

That said, a lot of people hate these .NET installer classes (and the default setup projects) altogether and implement true Custom Actions using a WIX or InstallShield based project.

Depending on what exactly you want to do and when you want to do it, you also introduce a .NET dependency. For example, if you are checking for .NET being installed, you won't be able to do this from a .NET custom action if the user does not have .NET already installed.

Adding Custom Actions is a bit of a slippery slope. Once people realize you can customize the installer, you'll likely be asked to do more and more. At that point it may make sense to use a more flexible tool (WIX (open source) or InstallShield ($)).

Upvotes: 0

Grant Thomas
Grant Thomas

Reputation: 45058

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.

Upvotes: 2

Related Questions