WixSystemToolExtension CopyFiles

Jan 10, 2012 at 12:59 PM


I am creating a upgrade MSI (wix 3.5) in order to create some patch on top of main install.

 I am try to use CopyFiles tag (msi extension 1.3 beta) inorder to take a backup of files before copying new files from upgrade MSI.

It taking backup of all the files but it looks it takes the backup after copying the new files from Wix upgrade. I need to take a backup of files before copying from wix. So that i can use them for un installation.

Is this possible, please let me know?

code snippet.

<AppSecInc:CopyFiles Id="CopyAll" CopyOnInstall="yes" Recurse="yes" Source="[MergeRedirectFolder]" Overwrite="yes" Target="[MergeRedirectFolder]\Backup" Wildcard="*.*" />


Also is there is any way we can take backup only the files which are copying in upgrade msi.




Jan 10, 2012 at 7:11 PM

You can override the sequence for the extension as a quick workaround.

            <Custom Action="Win32_CopyFiles_Immediate_Install" After="InstallFiles" Overridable="yes">NOT Installed</Custom>
            <Custom Action="Win32_CopyFiles_Deferred_Install" After="Win32_CopyFiles_Immediate_Install" Overridable="yes">NOT Installed</Custom>
            <Custom Action="Win32_CopyFiles_Immediate_UnInstall" Before="Win32_CopyFiles_Deferred_UnInstall" Overridable="yes">Installed</Custom>
            <Custom Action="Win32_CopyFiles_Deferred_UnInstall" Before="RemoveFiles" Overridable="yes">Installed</Custom>

Change those Before and After elements. 

If you have lots of time, you might want to implement a file backup extension that inspires heavily from Win32_CopyFiles that runs at different times and that can have parameters such as what is being backed up and where it backed up, then creates subfolders with some ID or date/timestamp.

Jan 11, 2012 at 6:39 AM

Thanks. Oh it uses a custom action at the End of day. I guessed that. Looks this is enough for me to complete my work.

Also After Uninstallation I need to copy these backup files to Original location, I guess I can make use of MoveFiles for this. If this not sufficient i will go for creating a custom action similar way Win32_CopyFiles.

Another quick question, I guess wix is going store list of installing files inside a table (for make use of uninstallation logic). Does the developer have access this table inside a Custom Action (i.e. May be inside a Session variable)? Sorry this is not related to msi extension, But if you can answer this it will be great.

Thanks Again.

Jan 11, 2012 at 2:59 PM

These are so called table-driven custom actions. There's a table in the MSI that is processed by an immediate CA, then put in a session variable that is read by a deferred CA, which actually does the work.

I think trying to save files over an installation is a very bad idea. You can have several scenarios that all fail in many different ways:

  1. Installation succeeds, then you uninstall, all is well.
  2. Installation backs up files, but then fails and rolls back. What now?
  3. Installation backs up files, succeeds, then uninstalls, but the backup files can't be copied back.
  4. You have an upgrade ...
  5. ... and many more

I would backup the files and leave it at that and wouldn't touch uninstall.

Jan 12, 2012 at 5:39 AM

Thanks. I got your point.

Shenoy S