One file per component or several files per component?
Asked Answered
L

2

70

Should I wrap all the files I want to install in individual components? What is the advantage of putting several files in one component?

Lucid answered 21/10, 2009 at 18:51 Comment(2)
Certain .NET assemblies are multi-file, but should be included in the same MSI component because they must be installed as an "atomic unit". In other words they should always install and uninstall together as a bundle.Gotham
Apart from multi-file .NET assemblies, I always use one file per component, because it avoids all kinds of upgrade and deployment issues.Gotham
B
90

One reason for "one file per component" is resiliency. When an application is started, Windows Installer can check whether the keypath of any component is missing. If the keypath is missing, the component is reinstalled/repaired.

If a component has multiple files, then only one file can be the keypath. In wix you indicate this by setting KeyPath=yes on a File element. The other files will then not be fully protected by Windows Installer resiliency. They will only be reinstalled if the keypath file goes missing.

Another reason to have "one file per component" is when installing files to locations where they may already be present (e.g. an application upgrade, or when installing to c:\windows\system32). Windows installer determines whether a component needs to be installed by checking the keypath. If the keypath is a file and the file is already there (with the same version or higher) then the component is not installed. That's a problem if the other files in the component actually needed to be installed/upgraded.

Blalock answered 22/10, 2009 at 0:11 Comment(11)
This is a great answer but doesn't say why the reverse is useful. Which is reasonable, as I only know of one advantage: you save some registration time during installation, as each component is registered, but each of its files is not. This is generally not a good tradeoff, as it kills resiliency and hinders upgrades, so pay more attention to wcoenen's recommendation.Spaniel
@Wim Coenen When using a "file per component" approach, one should put KeyPath="yes" on File, but what about its component? Is it necessary to add the same KeyPath="yes" on File's parent Component? Furthermore, what about Directory? What is the best practice with directories (empty and non empty)? Is there a good guidance on this? Thanks!!!Gastrolith
@zam6ak: comments are not the best place to ask new questions, as they get only limited attention and can't accommodate thorough answers. Please post a separate question instead of a comment!Blalock
@Wim Coenen Point taken! Here is the question: https://mcmap.net/q/104224/-wix-using-keypath-on-components-directories-files-registry-etc-etc/481904Gastrolith
@WimCoenen You said "When an application is started, Windows Installer can check whether the keypath of any component is missing." But, it's not always true. According to this site, "There are only certain entry points that trigger auto repair, such as advertised shortcuts, COM activation etc."Bomarc
@WimCoenen You said "If the keypath is a file and the file is already there (with the same version or higher) then the component is not installed." It may be helpful then to discuss non-versioned files (aspx, txt, etc) as it may be a reason to violate the one file per component guideline.Fulani
I do not understand why Wix doesn't support it implicitly :((( Why should I write all this boilerplate with including every single file into a separate component.Tubulure
Note that there are a few cases where several files always belong together and should be installed / uninstalled as a single unit. Multi-file .NET assemblies is just one such case. In these cases you should put all these files in the same MSI component to ensure they are handled together and not independently. Carefully set the appropriate key file for the group of files - the file that indicates whether all files should be updated / installed / uninstalled (preferably a versioned binary).Gotham
@SteinÅsmul Wrong. Wim's argument is just as important for this case - the only file that's being checked is the one that's "keypath". If you have several files that always belong together, they should be part of the same feature (and/or component group), but not the same component - otherwise you have no guarantee that they're all going to be installed (or repaired). Many of the failures of installers to repair installations boil down exactly to this - many different interdependent files in the same component. If the file that gets corrupted isn't the "keypath", tough luck.Sempstress
The deal is that some files belong together in "pairs", and shouldn't get "out of sync" - as in you shouldn't update just one of them. It happens, but it isn't that common a scenario.Gotham
@SergeyKostrukov: 9 years later, your feature request has been implemented with WiX 5 and its "naked files" feature: wixtoolset.org/docs/fivefour/#naked-filesHelbonnah
H
10

I follow the Microsoft approach which is also used by InstallShield: http://msdn.microsoft.com/en-us/library/aa368269(VS.85).aspx

The above link gives the advantages of this approach.

The relevant part is:

  1. Define a new component for every .exe, .dll, and .ocx file. Designate these files as the key path files of their components.
Homeland answered 8/8, 2011 at 18:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.