9

I have created an msi setup file which includes some files in a "Sample" folder which should be copied to a temp folder. Anybody suggest how to do this?

petert
  • 6,672
  • 3
  • 38
  • 46
Sukhjeevan
  • 3,074
  • 9
  • 46
  • 89

2 Answers2

10

Something like this:

   <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="MyVendor" Name="MyVendor">
            <Directory Id="INSTALLDIR" Name="MyDir">
                <Component Id="MyFileId" Guid="...G1...">
                    <File Id="MyFileId" Name="MyFile" Source="...blabla...\MyFile" KeyPath="yes" >
                    </File>
                </Component>


     <DirectoryRef Id="TARGETDIR">
            <Component Id="MyFileCopyId" Guid="...G2...">
                <RemoveFile Id="MyFileRemoveId" Name="MyFile" On="install" Directory="MyCopyDir" />
                <CopyFile Id="MyFileCopyId" FileId="MyFileId" DestinationDirectory="MyCopyDir" />
            </Component>


    <Feature Id="MyFeature" ... >
            <ComponentRef Id="MyFileId" />
            <ComponentRef Id="MyFileCopyId" />

The important Xml element is CopyFile. You need to create a new component that is a copy of the first one (with different ids, guids, ... of course). Both components needs to be declared in a feature.

Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • hi thanks for replying, I have some doubt 1).What would be the value of Guid.2).If i set DestinationDirectory="%TEMP%" then would myfile copied in temp folder.3).Can i set Source="myfile" attribute of File element. – Sukhjeevan Dec 06 '10 at 08:21
  • Guid2 is just a plain new guid. It has no relation with anything, but is needed for wix/msi. Your "temp" folder would be the MyCopyDir in the sample. Source is basically a local path, so you can put whatever you want, but you should have that part setup already in your wix file. It's unrelated with the copy. – Simon Mourier Dec 06 '10 at 08:30
  • You mean if i set DestinationDirectory="MyCopyDir" then myfile would be copied in ~[user]/LOCALS~1\Temp folder. I don't need to do anything else. – Sukhjeevan Dec 06 '10 at 09:24
  • 1
    Also I want to copy all files in "Sample" folder so in this case what would be the value of Source property of File element – Sukhjeevan Dec 06 '10 at 09:56
  • @Sukhi: Nest CopyFile under File and you would never guess what you need to put as Source – Yan Sklyarenko Dec 06 '10 at 10:01
  • I can't do like that because in "Sample" folder there are 100 files.Do i have to set Source=*.* for copying all files to temp folder. – Sukhjeevan Dec 06 '10 at 10:10
4

CopyFile element is your friend. You can nest it under the original File element a number of times, depending on how many times you need to copy it. Put the correct destination folder(s) and let Windows Installer do the rest.

Yan Sklyarenko
  • 31,557
  • 24
  • 104
  • 139
  • I can't do like that because in "Sample" folder there are more than 100 files.Do i have to set Source=*.* for copying all files to temp folder or something like that. – Sukhjeevan Dec 06 '10 at 10:13
  • 4
    Yeah, you can specify a wild card and have all the files in a folder copied to the destination. And this will probably quite elegant, as it requires one CopyFile element for the entire folder. However, if you generate the *.wxs file for this folder, you can consider applying an XSL transform to the output to add CopyFile to each file harvested. But that's an alternative, if the previous way works for you, keep to it :) – Yan Sklyarenko Dec 06 '10 at 12:18
  • Wish the WiX Toolset documentation had some useful demos, snippets etc. I try to get this working for hours now, I can't believe it! All I want is to make a copy of an existing file before I install an update. – Andreas Jun 27 '22 at 09:33