How to debug a .Net Installer Custom Action

ImportantThe following article uses options that are available starting with the Professional edition and project type.

A relatively easy way to debug a .NET Installer Class Action called during "Install" or "Uninstall", is to add the following lines to the source code of your custom action:

Sample - C#

using System.Windows.Forms;
using System.Diagnostics;

...

#if DEBUG
  int processId = Process.GetCurrentProcess().Id;
  string message = string.Format("Please attach the debugger (elevated on Vista or Win 7) to process [{0}].", processId);
  MessageBox.Show(message, "Debug");
#endif

....

Sample - VB.NET

Imports System.Windows.Forms
Imports System.Diagnostics

...

#If DEBUG Then
  Dim processId As Integer = Process.GetCurrentProcess().Id
  Dim message As String = String.Format("Please attach the debugger (elevated on Vista or Win 7) to process [{0}].", processId)
  MessageBox.Show(message, "Debug")
#End If

...

Once the .DLL file containing the custom action is generated add it to the project using the Files and Folders Page - Installer Project. In the Custom Actions Page add ".Net Installer Class Action" from the Add Custom Action Tab.

During the installation process a message box will appear displaying the process number of the installer.

In order to debug the custom action follow these steps:

  1. Start Visual Studio with elevated privileges and open the Custom Action project
  2. From the menu bar select Tools -> Attach to Process option
  3. In the newly opened dialog enable the Show processes from all users checkbox
  4. In the Available Processes list select the process with the ID displayed by the custom action dialog
  5. Click on [ Attach ] button to start debugging