2

I am trying to copy some of the files from installation location to other folder during install. When I set the SourceDirectory/SourceProperty to a hardcoded location the setup works fine as expected. But when I replace the SourceDirectory to "INSTALLFOLDER" then the files are not copied during install.

Here is the full source code,

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="FolderCopySetupProject" Language="1033" 
           Version="1.0.0.0" Manufacturer="Microsoft" 
           UpgradeCode="PUT-GUID-HERE">
    <Package InstallerVersion="200" Compressed="yes" 
             InstallScope="perMachine" />
    <MajorUpgrade DowngradeErrorMessage="Newer version installed." />
    <MediaTemplate EmbedCab="yes" />
    <Feature Id="ProductFeature" Title="FolderCopySetupProject" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
    </Feature>
  </Product>
  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="PE" />
      </Directory>
    </Directory>
  </Fragment>
  <Fragment>
    <Property Id="DestFilesFolder" Value="C:\Temp\" />
    <Component Id="cmpCC76E631D128DE73CBFBA4A3C6F364AC" Guid="*" 
               Directory="INSTALLFOLDER" KeyPath="yes">
      <File Id="filCDC69907319511E61137A95EF50FAB30"  Source="a.txt" />
      <File Id="filCDC69907319511E61137A95EF50FAB31" Source="b.txt" />
    </Component>

    <Component Id="CMP_LOG4TXT" Guid="*"  
               Directory="INSTALLFOLDER" KeyPath="yes">
      <CopyFile Id="Copy_LOG4TXT" SourceDirectory="INSTALLFOLDER" 
                SourceName="*" 
                DestinationProperty="DestFilesFolder"/>
    </Component>
    <ComponentGroup Id="ProductComponents">
      <ComponentRef Id="cmpCC76E631D128DE73CBFBA4A3C6F364AC" />
      <ComponentRef Id="CMP_LOG4TXT" />
    </ComponentGroup>
  </Fragment>
</Wix>

Here is the log file information,

Executing op: ComponentRegister(ComponentId={341BD660-7249-42DD-9744-DBEF0776AD52},KeyPath=C:\Program Files (x86)\PE,State=3,,Disk=1,SharedDllRefCount=0,BinaryType=0) MSI (s) (A0:64) [11:30:49:374]: Executing op: ActionStart(Name=CreateFolders,Description=Creating folders,Template=Folder: [1]) MSI (s) (A0:64) [11:30:49:375]: Executing op: FolderCreate(Folder=C:\Program Files (x86)\PE\,Foreign=0,,) MSI (s) (A0:64) [11:30:49:379]: Executing op: FolderCreate(Folder=C:\Program Files (x86)\PE\,Foreign=0,,) MSI (s) (A0:64) [11:30:49:380]: Executing op: ActionStart(Name=InstallFiles,Description=Copying new files,Template=File: [1], Directory: [9], Size: [6]) MSI (s) (A0:64) [11:30:49:381]: Executing op: ProgressTotal(Total=2,Type=0,ByteEquivalent=1) MSI (s) (A0:64) [11:30:49:381]: Executing op: SetTargetFolder(Folder=C:\Program Files (x86)\PE\) MSI (s) (A0:64) [11:30:49:381]: Executing op: SetSourceFolder(Folder=1\PE\) MSI (s) (A0:64) [11:30:49:381]: Executing op: ChangeMedia(,MediaPrompt=Please insert the disk: ,MediaCabinet=cab1.cab,BytesPerTick=65536,CopierType=2,ModuleFileName=C:\Windows\Installer\37a12097.msi,,,,,IsFirstPhysicalMedia=1) MSI (s) (A0:64) [11:30:49:381]: Executing op: FileCopy(SourceName=a.txt,SourceCabKey=filCDC69907319511E61137A95EF50FAB30,DestName=a.txt,Attributes=512,FileSize=1,PerTick=65536,,VerifyMedia=1,,,,,CheckCRC=0,,,InstallMode=58982400,HashOptions=0,HashPart1=-1183465204,HashPart2=-1464405568,HashPart3=-493239503,HashPart4=1629910889,,) MSI (s) (A0:64) [11:30:49:382]: File: C:\Program Files (x86)\PE\a.txt; To be installed; Won't patch; No existing file MSI (s) (A0:64) [11:30:49:382]: Source for file 'filCDC69907319511E61137A95EF50FAB30' is compressed

Looks like the files are not available in the "INSTALLFOLDER" for copying, I am not sure how to sequence the Components to execute in order. (InstallExecuteSequence On="AfterInstall" something like that)

Anyhelp would be very much appreciated

Thanks, Rajesh

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
Rajesh
  • 240
  • 3
  • 8

3 Answers3

1

Perhaps you can try the CopyFile element. Better yet: use your application's launch sequence to do any file copying on first launch to avoid entangling this operation with your setup.

Copy file from setup location to another location in wix on install

Community
  • 1
  • 1
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • Hi, Thanks for looking into it, but I am already using CopyFile element and it works fine when I have source and destination directory as hardcoded paths, whereas when I replace the "INSTALLFOLDER" instead of hardcoded path, the issue happens and I have added the log file also – Rajesh Aug 26 '14 at 05:06
  • I think the only attribute required for CopyFiles is **DestinationProperty**. Also the temp directory is already resolved by the windows installer property [**TempFolder**](http://msdn.microsoft.com/en-us/library/aa372067(v=vs.85).aspx). Never install files with GUIDs to the temp folder, [**self-repair problems**](http://stackoverflow.com/questions/5501028/how-can-i-determine-what-causes-repeated-windows-installer-self-repair/6066263#6066263) could result. – Stein Åsmul Aug 26 '14 at 15:19
  • The problem is most likely that you have generated a MoveFiles action instead of a DuplicateFiles action. MoveFiles is required to be before InstallFiles so there's nothing to copy. You need to do whatever is required to turn the MoveFiles into a DuplicateFiles. There's something you can do with WiX CopyFile element that will populate the MSI's DuplicateFile table. I forget the details - take a look at the docs - but if you look at your final MSI file with Orca and the stuff is in the DuplicateFile table then you've probably got it right. DuplicateFiles copies files AFTER they're installed. – PhilDW Aug 26 '14 at 20:16
  • Thanks Phil, I further analysed and found that Wix has limitations in copying a folder to multiple locations during installation, someone have faced the same issue earlier in this link, http://stackoverflow.com/questions/5356905/how-to-copy-a-folder-not-a-file-during-installation-with-wix – Rajesh Aug 27 '14 at 05:56
1

I have faced exactly the same situation and was able to solve that.

<CustomAction Id="BaselineSync_Cmd" Property="BaselineSync" Execute="immediate"
    Value="&quot;robocopy&quot; &quot;[BUP]&quot; &quot;[PROD]&quot; /PURGE /e" />
<CustomAction Id="BaselineSync" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="ignore" Impersonate="no"/>
<CustomAction Id="RoboCopy_Cmd" Property="RoboCopy" Execute="immediate"
    Value="&quot;robocopy&quot; &quot;[INSDIR]&quot; &quot;[PROD]&quot; /e" />
<CustomAction Id="RoboCopy" BinaryKey="WixCA" DllEntry="CAQuietExec" Execute="deferred" Return="ignore" Impersonate="no"/>

<InstallExecuteSequence>
    <Custom Action="BaselineSync_Cmd" After="StartServices"><![CDATA[NOT(Installed) AND (PROD <> "") AND (BUP <> "(none)")]]></Custom>
    <Custom Action="BaselineSync" After="BaselineSync_Cmd"><![CDATA[NOT(Installed) AND (PROD <> "") AND (BUP <> "(none)")]]></Custom>
    <Custom Action="RoboCopy_Cmd" After="BaselineSync"><![CDATA[NOT(Installed) AND (BUP <> "") AND (INSDIR <> "(none)")]]></Custom>
    <Custom Action="RoboCopy" After="RoboCopy_Cmd"><![CDATA[NOT(Installed) AND (BUP <> "") AND (INSDIR <> "(none)")]]></Custom>
</InstallExecuteSequence>

What happens here is as follows: When we call the installer we are passing three variables, INSDIR, BUP and PROD. These are paths.

The contents of the installer are pushed out to the value of INSDIR. Then the files and folders in BUP are copied over to the files and folders in PROD. We have a /PURGE operation which means that PROD is first deleted. Once the files of BUP are copied over to PROD, we copy the files/folders of INSDIR over PROD and overwriting the contents. This has been working perfectly for me.

Sourav Kundu
  • 408
  • 2
  • 14
0

As of now, Wix is not capable of copying the folder to multiple locations during install

Although this is a common scenario, but Wix cannot handle this

How to copy a folder (not a file) during installation with WiX?

Community
  • 1
  • 1
Rajesh
  • 240
  • 3
  • 8