[wix-users] Strategies for Reducing Installer Code Duplication
egcastr at gmail.com
Fri Sep 18 14:39:39 PDT 2020
On Fri, Sep 18, 2020 at 1:05 PM Todd Hoatson via wix-users <
wix-users at lists.wixtoolset.org> wrote:
> And I believe that ComponentGroups are typically defined along with the
> components. But consider the following:
> <ComponentGroup Id="ProductComponents" Directory="MyProgramDir">
> <ComponentRef Id=" Comp1" />
> <Fragment Id="CompFrag">
> <Component Id="Comp1" .../>
> <Component Id="Comp2" .../>
> <Component Id="Comp3" .../>
> Given that the components are defined in their own fragment, would a
> reference to one component in the ComponentGroup bring all the others into
> the same group? What if I wanted them to end up in different groups?
> Would the components each need to be in their own fragment, as heat does?
No. The reference for Comp1 does not automatically reference Comp2 or
Comp3. They must be referenced individually.
Consider a native C or C++ program. When you compile a C source file
(compilation unit) the C compiler generates an object code file with all
the object code in that compilation unit. Later on you link multiple object
code files, along with object code files in libraries, into a single
executable. All functions in the compilation unit are linked into the
resulting executable regardless of whether some of those functions are
called directly or indirectly from the main function. Any function that was
linked in but not called wastes some space in the resulting executable.
WiX follows a very similar organization. Fragments are like C compilation
units. Components are like C functions. You can think of a Feature like a
special function (similar to main). In WiX, each Product (think C
executable) must have one or more Features and the user selects which of
these Features are installed, at least one must be installed. In C there is
only one main function but the analogy still works. Similarly, C source
files can only have one compilation unit while a WiX source file can have
multiple Fragments but the analogy still holds.Using this analogy,
ComponentRefs are like function calls in C. The C main function will call
other functions in the same way that Features will install referenced
Components. WiX gives you a lot of ways to reference (call in the analogy)
In C the linker examines data about function calls to determine which
functions it needs to link (included) into the resulting executable. But it
cannot link individual functions, it must bring along the entire
compilation unit regardless of whether all the functions in that
compilation unit are called or not.
Similarly, the WiX linker looks at Component references to decide which
Components need to be linked (included) into the resulting MSI. But it
cannot link individual Components, it must bring in the entire Fragment
(including non-Components) regardless of whether all the Components in the
Fragment are referenced.
In C to use a function you must call it directly or indirectly from main.
In Wix to install a Component you must reference it directly or indirectly
from a Feature.
Edwin G. Castro
More information about the wix-users