[wix-users] `File/@Name` doesn't work as expected when nested under `Component/@Directory`

Armen Michaeli armen.michaeli at gmail.com
Fri May 1 05:23:56 PDT 2020

>From what I understand, per the "How To: Specify source files" page
and as briefly touched upon by the "Component Element"
and "File
Element" <https://wixtoolset.org/documentation/manual/v3/xsd/wix/file.html>
pages, when a file is specified using the File/@Name attribute, it is
effectively accessed by name relative to the directory of the component the
file is part of. The component's directory, in turn, is ideally understood
(by me) to be either the directory specified by the nearest ancestor
Directory element, *or* by the Component/@Directory attribute, if present.

Needless to say, the following works as expected:

<Directory Id="INSTALLDIR" Name="Foobar" FileSource="!(wix.SOURCEDIR)">
        <File Name="README.txt" />

The following, however, does not:

<Directory Id="INSTALLDIR" Name="Foobar" FileSource="!(wix.SOURCEDIR)" />
    <Component Directory="INSTALLDIR">
        <File Name="README.txt" />

I am surprised. Is the behaviour intended by design, an omission or
something else? The "How To: Specify source files" page

When you use the File/@Name attribute and don't use the File/@Source
attribute, the compiler constructs an implicit path to the file based on
the file's parent component directory plus the name you supply.

In case of the second snippet above, the component's directory *is
specified* (INSTALLDIR), is it not? Why can't the file be found? It seems
that WiX only actually wants to use the directory based on element
parent-child relationship, not the one created by the Component/@Directory
attribute value.

I am using candle.exe and light.exe, it is the linker/binder (the latter)
that produces the LGHT0113 error.

WiX version
.NET version 3.1.201 (dotnet --version)

More information about the wix-users mailing list