How do I implement self-healing into the application?

When developing an installation package for your application, it's always a good idea to implement a self-healing mechanism. This way, if the installation somehow becomes broken or corrupt, it will be repaired automatically.

Windows Installer addresses this feature through Advertised shortcuts. Suppose you have a package which installs three files: MyApp.exe, MyResource.dll and ReadMe.txt. Since the first two files are essential to the application, we will add them to "Main Feature" in the Organization page. The .TXT file does not affect the application, therefore we can add it under another feature (for example "Secondary"). The "Organization" page would look like this:

Main Feature

After we organized the installation, we can create the advertised shortcuts for MyApp.exe. For this example, let's create them on the Desktop (in the "Desktop" folder) and in the Start Menu (in the "Application Shortcut Folder" directory). An advertised shortcut is created like any other shortcut, except it has the Advertised shortcut option checked in the Shortcut Properties Dialog.

When the application is installed, the self-healing feature is automatically activated if the application is launched through the advertised shortcuts. Since the shortcuts point to a file in Main Feature, only the components in this feature can be repaired. Therefore, if one of these components is missing, Windows Installer will trigger an auto-repair for the entire feature.

However, if a component from the other feature is missing (for example, "ReadMe.txt" was deleted), Windows Installer will not trigger a repair. This is because the advertised shortcut verifies only the feature which contains it's target.