Q:

CustomAction Called Twice

I use Wix, and have a customAction and a anb installSequence:
 <CustomAction Id='PreInstallAction' BinaryKey='PreInstallBinary' DllEntry='MyCustomAction1' Execute='immediate'
                  Return='check'/>
      <Binary Id='PreInstallBinary' SourceFile='E:\...\MyCustomAction\bin\Release\MyCustomAction.CA.dll'/>

      <InstallExecuteSequence>
         <Custom Action='PreInstallAction' Before='InstallInitialize'/>
      </InstallExecuteSequence>

The problem is that my custom action is called twice - (In the custom action I print things into the log file and I see them twice)
I tried to comment the line:
 <MajorUpgrade AllowDowngrades="no" AllowSameVersionUpgrades="yes" DowngradeErrorMessage="Can't downgrade from newer version"  />

And it solved the problem.
But I need the major update so I tried uncomment the above line and add a condition to the customAction:
<InstallExecuteSequence>
         <Custom Action='PreInstallAction' Before='InstallInitialize'>
            NOT Installed AND NOT PATCH
         </Custom>
      </InstallExecuteSequence>

But now ny customAction is called twice again...
Is anything wrong with my condition? I s there any other solution?

A:

Your custom action is executing twice because it's in the execute sequence of both the new and old install.  When RemoveExistingProducts performs the major upgrade it's actually running the uninstall of your old product so both come into scope.  You could fix this by placing a conditional expression on the sequencing of the custom action so that it only runs during uninstall of the old or the install of the new.  
Also, depending on what this CA is actually doing, Immeadiate execution scheduling may not be the best option.  Any custom action that changes the state of the machine must be scheduled between InstallInitialize and InstallFinalize with Deferred ( usually System Context ) Execution to ensure propert rights and rollback behavior ( you have to author the rollback and commit actions also ).

