Invalid DefaultDir when running light in WiX

2019-07-04 05:32发布

问题:

I simply want to do an installer that will move some files into Program Files, set up a start menu link, and appear in the add/remove program to be uninstalled. For the time being I'm happy to punt on the start-menu link as that seems relatively straight forward

The caveat is that I specifically want this to be build-able from a script without any sort of global installs. That means no Visual Studio extension nor any global installation of the WiX toolkit.

I was able to find WiX on nuget which seems to come with all the correct executables packaged. So I would like to use these. I set up aliases for candle, light, and heat to draw from the tools/ directory.

To start with, I create a very simple file structure that I want moved into Program Files/Foo

/temp/SourceDir/
  |- bar.txt
  |- one.txt
  |- afolder/
     |- baz.txt

I also use a WixSample project and some recommendations to create the following /temp/foo.wxs:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
    <!-- Use * to generate product ID on every build -->
    <Product Id="*" Language="1033" Manufacturer="gim" Name="Foo Sample" UpgradeCode="1750d746-841f-4a27-a0ba-661b093dac23" Version="1.0.0.0">
        <Package Comments="comments!" Compressed="yes" Description="Attempting to learn Wix" InstallScope="perMachine" Manufacturer="gim"/>
        <MediaTemplate EmbedCab="yes"/>
        <!--Directory structure-->
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="DYNAMIC" Name="Dynamic"/>
            </Directory>
        </Directory>
        <!--Features-->
        <Feature Id="AllOfTheFiles">
            <ComponentGroupRef Id="CMPG_AllOfTheFiles"/>
        </Feature>
    </Product>
</Wix>

I then run

temp> heat dir W:\temp\SourceDir\ -cg CMPG_AllOfTheFiles -ke -dr DYNAMIC -gg -sfrag -o .\Dynamic.wxs

Which generates Dynamic.wxs

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs">
    <Fragment>
        <DirectoryRef Id="DYNAMIC">
            <Directory Id="dirGQx5YQf5IXUdDl9BwSUIwBDODsQ" Name="SourceDir">
                <Component Id="cmpGDFXrG8sOAaKgy928OXqQ2tfoYI" Guid="{19459DB2-B1C7-4981-A0B9-F1CA0027B458}">
                    <File Id="fil9Q22BRrI_M6KyGIXyzknyYKsXYM" KeyPath="yes" Source="SourceDir\bar.txt" />
                </Component>
                <Component Id="cmpiuJCUGMxrseFgAzuyEWugfL6co0" Guid="{C09CEC2D-675C-438A-815D-E97D80B46579}">
                    <File Id="filJdeJM1_v6rytDwKRYjkJ6S4Ukos" KeyPath="yes" Source="SourceDir\one.txt" />
                </Component>
                <Directory Id="dir1V3jm.snhkr1aYM.1IgU9rhSuSM" Name="afolder">
                    <Component Id="cmpnBgBnytwthO6y_QeTGG7n0P_cSw" Guid="{4AAC9123-F1FE-4DFF-B7EB-1D0A7053ECF9}">
                        <File Id="filDNjPHE_Pp2VbCtvIxLyegx_2prU" KeyPath="yes" Source="SourceDir\afolder\baz.txt" />
                    </Component>
                </Directory>
            </Directory>
        </DirectoryRef>
    </Fragment>
    <Fragment>
        <ComponentGroup Id="CMPG_AllOfTheFiles">
            <ComponentRef Id="cmpGDFXrG8sOAaKgy928OXqQ2tfoYI" />
            <ComponentRef Id="cmpiuJCUGMxrseFgAzuyEWugfL6co0" />
            <ComponentRef Id="cmpnBgBnytwthO6y_QeTGG7n0P_cSw" />
        </ComponentGroup>
    </Fragment>
</Wix>

I then run

temp> candle .\foo.wxs
temp> candle .\Dynamic.wxs

Which generates a wixobj for each.

Finally I try to light these.

temp> light .\foo.wixobj .\Dynamic.wixobj -o .\foo.msi -nologo
W:\temp\Dynamic.wxs(5) : error LGHT0204 : ICE03: Invalid DefaultDir string; Table: Directory, Column: DefaultDir, Key(s): dirGQx5YQf5IXUdDl9BwSUIwBDODsQ

At this point I'm stumped. I have no idea what this error means nor how to fix it - why is that directory causing issue?

回答1:

SourceDir is a reserved name for a directory in the msi table I believe. It references the dir where the msi file that is being run is located. So light complains when you are trying to create another directory with name "SourceDir" for the dir with id "dirGQx5YQf5IXUdDl9BwSUIwBDODsQ"

Try renaming W:\temp\SourceDir to something else