?
Solved

WiX Installer copy files before uninstall previous version

Posted on 2013-12-09
7
Medium Priority
?
2,227 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
Monitor input from a computer is usually nothing special.  In this instance it prevented anyone from using the computer.  This was a preconfiguration that didn't work.
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…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

765 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