Thursday, October 02, 2008

Debugging installer classes

There are many blog posts which describe clumsy workarounds to debug installer classes but certainly not the best way to achieve it.

There are two scenarios:

  1. You really need to debug your installer class in the msiexec.exe process, and you need to buy some time to be able to attach the Visual Studio debugger to this process (menu Debug -> Attach to Process… in Visual Studio). One way to buy time is to popup a message box to halt the execution of the install method while you are attaching your debugger to the process. For more information, see
  2. You can also conveniently run your installer class using the installer tool (InstallUtil.exe). If this scenario works for your debugging requirements:
    1. Open the properties of the project containing your installer class (right-click the project in the solution explorer of Visual Studio and select contextual menu option Properties);
    2. Check the assembly name on the Application tab. In our example, the assembly name is "AssemblyName", and since our project is a class library the assembly is "AssemblyName.dll";
    3. Go to the Debug tab and in the Start Action, select Start external program and enter "C:\Windows\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe";
    4. On the same tab, in the start Options, enter the following command line arguments: "AssemblyName.dll /LogToConsole=true" according to point b.
      Open your installer class in the code editor and at the top of the install method (assuming you are debugging the installation) add:
      #if DEBUG
      if (System.Diagnostics.Debugger.IsAttached)

    5. Set your project as startup project, press F5 or start debugging in Visual Studio and the debugger will automatically stop on the Debugger.Break() statement.

1 comment:

Taxanomy said...
This comment has been removed by the author.