Solved

WiX Installer copy files before uninstall previous version

Posted on 2013-12-09
7
2,036 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
  • 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
If you don't know how to downgrade, my instructions below should be helpful.
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

773 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