WiX Remove files on uninstall but not update

你说的曾经没有我的故事 提交于 2021-02-10 09:24:55

问题


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.


回答1:


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>



回答2:


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?> 


来源:https://stackoverflow.com/questions/25450864/wix-remove-files-on-uninstall-but-not-update

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!