10

I'm trying to make an install that puts a copy of the same files in multiple places...

is there a simple way to do this?

eg. if I wanted to put a.txt b.txt c.txt into all of the following directories :-

.\Blah\
.\Txts\
.\Examples\

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156

2 Answers2

14

Simply create multiple components which reference the same file, but install it to different locations. The only gotcha is that you cannot use two <File Source="somefile"/> elements referencing the same file because they will get the same auto-generated ID. Explicitly give the file elements different IDs to avoid that problem.

<DirectoryRef Id="directory1">
   <Component Id="somefile-component1">
      <File Id="somefile-id1" Source="/path/to/somefile"/>
   </Component>
</DirectoryRef>

<DirectoryRef Id="directory2">
   <Component Id="somefile-component2">
      <File Id="somefile-id2" Source="/path/to/somefile"/>
   </Component>
</DirectoryRef>
Wim Coenen
  • 66,094
  • 13
  • 157
  • 251
  • yeah, I kindda figured I could do that, but thats painful, it means seperate IDs and GUIDs, etc etc. The other option is CopyFile it seems, but then you have to handle the uninstall of them – Keith Nicholas Oct 13 '09 at 20:33
  • You could also use the same components in multiple installers which each define the referenced directory differently. But then you'll end up with multiple MSI files. Would you like for me to elaborate on that approach? – Wim Coenen Oct 13 '09 at 23:09
  • 2
    I'll accept this answer as this was what I ended up effectively doing. I don't like the idea of all the duplication so I ended up writing a program that generated the Wix xml for me and handled automatically the duplication. Feels like wix is too raw and a higher level of abstraction is needed to write installers. – Keith Nicholas Oct 18 '09 at 20:14
  • @WimCoenen How does this effect the size of the installation? – Sergei Golos Jul 17 '12 at 21:11
  • 2
    @SergeiGolos: it does not increase the size, [smart cabbing](http://robmensching.com/blog/posts/2007/6/1/quotSmart-cabbingquot-added-to-WiX-toolset) will make sure that the content of the file is included only once. – Wim Coenen Jul 18 '12 at 09:13
7

Duplicate Files: Windows Installer has its own concept for this called "DuplicateFiles". It only works if the files are actually identical, but it sounds like that's what you want.

CopyFile Element: In WIX you implement this via the CopyFile element:

http://wix.sourceforge.net/manual-wix2/wix_xsd_copyfile.htm

I haven't actually tried it, but it should look something like this

<Component Id='Manual' Guid='*' >
  <File Id='Manual' Name='Manual.pdf' Source='Manual.pdf' KeyPath='yes'>
    <CopyFile  Id='MyDuplicateFile1' DestinationProperty ='DesktopFolder'/>
  </File>
</Component>
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • Yes, it actually does - as long as component that did the duplication is being uninstalled (it might not be if it was set permanent). – Stein Åsmul Oct 14 '09 at 14:44
  • When the File element has an `condition`, will CopyFile also validate the condition? – KargWare Apr 07 '20 at 07:22