Skip to content

Phases Overview

Richard Martin edited this page Mar 25, 2024 · 2 revisions

The installation of the bundle happens in three phases.

  1. Detect
  2. Plan
  3. Apply

The classes in the Bootstrapper.Phases namespace contain event handlers for these phases. These classes direct and manage the install. The events are triggered while Windows Installer works on evaluating and applying the bundle.

HRESULTs

Both Windows Installer and WiX use HRESULTs to provide the result of operations. Most event arguments (if not all) passed to your handlers have an HResult property that you can use to pass an HRESULT back to the engine. Events that report completion of tasks include an additional Status property which contains the engine's HRESULT of that operation.

I suggest not using the HResult property to report errors. Throw an exception instead. I've found returning an HRESULT back to be hit and miss. Sometimes the install will fail and roll back appropriately, but other times the result is ignored. Throwing an exception does a better job of getting the engine's attention.

You can, and probably should, check the Status property for engine results and handle them appropriately. A good time to do this is when a phase completes.

if (ErrorHelper.HResultIsFailure(e.Status))
{
    // Handle result
    return;
}

Exceptions

I suggest logging all exceptions in your event handlers. Don't count on WiX to log them for you.

try
{
    // Handle event
}
catch (Exception ex)
{
    log.Write(ex);
    throw;
}

Previous: AppState Class || Next: DetectPhase Class

Clone this wiki locally