Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

WiX Installer copy files before uninstall previous version

Posted on 2013-12-09
7
Medium Priority
?
2,293 Views
Last Modified: 2013-12-10
In the WiX installer, or just in a .msi file, is it possible to copy files before the program uninstalls the previous version?

The previous version has a database and user settings files. I want to copy those to a temp directory, then copy them to the installed directory after the installer installs the new version.

I currently have
      <MajorUpgrade
        Schedule="afterInstallInitialize"
        DowngradeErrorMessage="A later version of [ProductName] is already installed. Setup will now exit." />

Open in new window

I could change the uninstall to later if that helps.

Should I use a custom action that runs a batch file or something, or can I do the copy within WiX using CopyFile, FileExists, stuff like that? Example?
0
Comment
Question by:deleyd
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39707335
Most likely you don't need to do anything. Read article "How Windows Installer handles file replacement logic for versioned and unversioned files" , especially the paragraph that begins with "In the case when both files are unversioned and have file hashes". In your case, if the user changed those files, their created time and modified time will be different, so they won't be replaced.
0
 

Author Comment

by:deleyd
ID: 39707568
Well in my case the MajorUpgrade uninstalls any previous version after InstallInitialize,before the installer actually installs new files, so the old files are already gone.

Plus we're changing the location where we install the files, so we're not installing on top of an old install, because the previous install is in a different location.
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39707718
Then definitely custom action. Because the execution phase of your new installation will be running after the old version has already been uninstalled.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:deleyd
ID: 39708467
I can't seem to execute a custom action, such as a .bat batch file, early on, before the uninstall. I'm guessing because the .bat batch file hasn't been installed yet.

The doc says if I schedule the uninstall after InstallExecute, then I need to have "strict adherence to the component rules." That's the phrase that I'm unsure of what they mean by that.

It's a simple install with only a couple dozen files. However the number of files does change. I have each file listed as a separate component. e.g.:
            <Component Id="C__DataAndLogic.dll" Guid="{4027F0C8-8A03-3B33-7B47-CC68F842EDB6}">
                <File Id="FILE_DataAndLogic.dll" Name="DataAndLogic.dll" KeyPath="yes"
                Assembly=".net" AssemblyManifest="FILE_DataAndLogic.dll" AssemblyApplication="FILE_DataAndLogic.dll" DiskId="1"
                  Source="..\binaries\DataAndLogic.dll" />
            </Component>

Open in new window

As long as I do that does that mean I'm adhering to the "component rules"?
0
 
LVL 40

Expert Comment

by:Vadim Rapp
ID: 39708484
> I can't seem to execute a custom action, such as a .bat batch file, early on, before the uninstall. I'm guessing because the .bat batch file hasn't been installed yet.

Right, no files. Can be .vbs or .js script, actions 5 / 6.

>  I need to have "strict adherence to the component rules." That's the phrase that I'm unsure of what they mean by that.

In a nutshell, don't add new files to the existing components. More in the section "Organize the installation of your application around components" of Windows Installer Best Practices.
0
 

Author Comment

by:deleyd
ID: 39708512
If I stick with the "one file per component" format, then am I following the "component rules"? (I recall somewhere reading the WiX developers went with "one file per component" for some reason.)
0
 
LVL 40

Accepted Solution

by:
Vadim Rapp earned 2000 total points
ID: 39708548
>If I stick with the "one file per component" format, then am I following the "component rules"? (

Yes, you do.

>  WiX developers went with "one file per component" for some reason

Looking at the reasons (if this discussion reflects them accurately), I'd absolutely disagree. The desire to have full resiliency, provided by every file being the keypath of its component, will often result in Installer's attempts to self-repair, and these attempts practically always will be unneeded; further, the user probably won't have the installation source ready when self-repair requests it, so it all will be nothing but frustration. For that reason, I'd rather recommend to have components without the keypaths at all - those that can be changed by the application for sure, and also unversioned files.

WiX developers sure can have their own views, but I don't think that WiX itself enforces these practices in any way. You can build your installation the way you want.
0

Featured Post

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For a while now I'v been searching for a circular progress control, much like the one you get when first starting your Silverlight application. I found a couple that were written in WPF and there were a few written in Silverlight, but all appeared o…
Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

618 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question