With Visual Studio Installer Project, you can add Custom Actions, which are custom scripts that can be executed during the installation process.
Windows Installer – Using Custom Actions
However, in the Custom Actions View of Visual Studio Installer Project, there are only four predefined stages: Install, Commit, Rollback and Uninstall. It’s not very clear which stage to perform actions before the installation.
I found a way to add custom actions that run before the installation starts.
I introduce it below…

Creating a Class Library using Installer.Install() base class
Custom Actions supports VBScript(.vbs), JavaScript(.js), Execution(.exe) and Class Library(.dll). In this time, I use Class Library(.dll) to inherit features of the Installer Class.
Installer Class – (System.Configuration.Install)
Create a Class Library project in Visual Studio
Create your new project for the Class Library. Open the Visual Studio, create a new solution. From “Add > New Project…” select the “Class Library (.NET Framework)”.
Creating and Using DLL (Class Library) in C#
Create a Class that inherits from Installer Class
- Add Reference to System.Configuration.Install in the Project.
- Define the namespace with “using System.Configuration.Install;”
- Define the new class inherits from the Install class.
- Add “RunInstaller” Attribute to notify the Visual Studio Custom Action Installer that needs to be invoked when the assembly is installed.
- Override Install() method.
- In the Install() method, add custom actions you want to add before calling the base class Install();
[RunInstaller(true)]
public class CustomInstallation : Installer
{
public override void Install(IDictionary stateSaver)
{
CustomAction1();
CustomAction2();
base.Install(stateSaver);
}
}
You can use “OnBeforeInstall()” method as well.
With my experiment, the Installer() method is called first, and after that the OnBeforeInstall() method is called. I checked it by add “Form.ShowDialog()” in each method.
Get the .dll file by building the project
After the implementation of the CustomInstallation Class done, Build the project to get the .dll file. You can see it in the Release folder.
Add the .dll file to the Visual Studio Installer Project
- Go to your Visual Studio Installer Project.
- Right click on the Installer Project name. Select “View” > “File System”.
- Select “Add” > “File” to add the .dll file you created.
- Right click on the Installer Project name. Select “View” > “Custom Action”.
- In the “Install” stage, Add the .dll file.
- Build the Installer Project and get the Setup.msi file.
Leave a comment