Solved

WiX Installer copy files before uninstall previous version

Posted on 2013-12-09
7
2,178 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
Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

 

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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

As more and more people are shifting to the latest .Net frameworks, the windows presentation framework is gaining importance by the day. Many people are now turning to WPF controls to provide a rich user experience. I have been using WPF controls fo…
Installations often have prerequisites, such as “Microsoft .Net framework is required for this product”. The usual implementation in MSI installations is system search for a particular registry setting representing the required prerequisite, followe…
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…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

695 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