2

I have an app that can log when given the correct flags at install time (/logLevel=debug on install gets passed to the app when the service starts). Our update process is a automated uninstall then install with a new MSI package. I know there is built in patch functionality with WiX, but this is our process.

Similarly with the logLevel parameter, I'd like to pass something to the effect of UPDATE="true" on the command line during uninstall. When this parameter is passed to the uninstaller it should not delete the log files. Currently we delete the files every time, but would like to retain the log files during an update. This is what I am trying to extend as of right now:

<?if $(var.BUILD_CONFIG) = "Debug" ?> 
<?else?>
  <CustomAction Id="Cleanup_logfile" Directory="TempTest"
   ExeCommand="cmd /C &quot;del %systemroot%\temp\hexis_hawkeye_g.log.*&quot;"
   Execute="deferred" Return="ignore" HideTarget="no" Impersonate="no" />

  <InstallExecuteSequence>
    <Custom Action="Cleanup_logfile" Before="RemoveFiles" >
      REMOVE="ALL"
    </Custom>
  </InstallExecuteSequence> 
<?endif?> 

And I've been playing with code similar to something like the following but it doesn't seem to work:

<?if $(var.BUILD_CONFIG) = "Debug" ?> 
<?else?>
  <?if '[UPDATE]' = "true" ?>
  <?else?>
    <CustomAction Id="Cleanup_logfile" Directory="TempTest"
     ExeCommand="cmd /C &quot;del %systemroot%\temp\hexis_hawkeye_g.log.*&quot;"
     Execute="deferred" Return="ignore" HideTarget="no" Impersonate="no" />

    <InstallExecuteSequence>
      <Custom Action="Cleanup_logfile" Before="RemoveFiles" >
        REMOVE="ALL"
      </Custom>
    </InstallExecuteSequence> 
  <?endif?>
<?endif?>

I'm not sure if I'm not initializing the UPDATE variable correctly, or if this really is some pre-processing that cannot be implemented in this fashion. I would think it would not work because these constructs are described on the preprocessor doc page, however, the /logLevel and various other parameters seem to work fine at run-time installation. I'm totally WiX illiterate and have been trying to read their documentation to no avail, any helpful links appreciated.

Danny A
  • 323
  • 1
  • 4
  • 14

2 Answers2

3

The problem as I see it: during a major upgrade when the application is uninstalled (and later on installing the new version) REMOVE=ALL is also true during uninstalling the application, so the files will be deleted.
You need to additionally check if the UPGRADINGPRODUCTCODE is also set or not, which would only be true during an update.

Check this answer where the correct condition is given (and bookmark the question as I did, it is very very useful for all the possible states and conditions ;-)).

The correct condition should be the following in your case:

<InstallExecuteSequence>
  <Custom Action="Cleanup_logfile" Before="RemoveFiles" >
    (NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
  </Custom>
</InstallExecuteSequence>
Community
  • 1
  • 1
taffit
  • 1,979
  • 22
  • 23
  • Thanks for your help, it doesn't seem like an easy subject to get help on. My concern with this solution is that UPGRADINGPRODUCTCODE is for updates, however, our update procedure is just uninstall then install using `msiexec.exe /i` then `msiexec.exe /x`. I guess I could set this on the command line manually? Like so: `msiexec.exe /x {blah-blah} UPGRADINGPRODUCTCODE=1` I wouldn't have to change my GUID right? – Danny A Aug 26 '14 at 13:01
  • Sure, but if you have access to the command line on which parameter to handle over to the Windows Installer it is maybe better to choose some other property than a built-in one, e.g. `ITSANUPDATE` and then check if it is set or not, i.e.: `(NOT ITSANUPDATE) AND (REMOVE="ALL")`. – taffit Aug 26 '14 at 13:57
  • So I think I found a solution using `INSTALLLEVEL` instead of `UPGRADINGPRODUCTCODE`. The problem with using something like `ITSANUPDATE` is that WiX doesn't allow this property. When I run the uninstaller as you said I get `MSI (s) (C8:70) [15:07:39:891]: Ignoring disallowed property UPDATE`. I tried getting this to work by setting a property but it didn't seem to take. Maybe I did something wrong there. – Danny A Aug 26 '14 at 19:10
  • 1
    You have to mark the property as secure so that it is available in all phases of the installation / uninstallation, i.e. write it all uppercase and on definition add the `Secure`-attribute and set it to `yes`, i.e. ``. This way the error message should not appear anymore. – taffit Aug 28 '14 at 14:03
  • This worked for me (finally). Thanks so much for your help @taffit, much better than my suggestion below. – Danny A Aug 29 '14 at 13:33
0

This is probably a bit hackish, but I was able to pass what I wanted by insinuating from the LOGLEVEL what action to take instead of passing an arbitrary variable:

msiexec.exe /x {blah-blah-guid-blah} INSTALLLEVEL=2

And for the configuration of my custom action:

<?if $(var.BUILD_CONFIG) = "Debug" ?> 
<?else?>
  <CustomAction Id="Cleanup_logfile" Directory="TempTest"
   ExeCommand="cmd /C &quot;if [INSTALLLEVEL] GEQ 2 del %systemroot%\temp\hexis_hawkeye_g.log.*&quot;"
   Execute="deferred" Return="ignore" HideTarget="no" Impersonate="no" />

  <InstallExecuteSequence>
    <Custom Action="Cleanup_logfile" Before="RemoveFiles" >
      REMOVE="ALL"
    </Custom>
  </InstallExecuteSequence> 
<?endif?> 
Danny A
  • 323
  • 1
  • 4
  • 14