4

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?

Community
  • 1
  • 1
George Mauer
  • 117,483
  • 131
  • 382
  • 612

1 Answers1

3

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

Brian Sutherland
  • 4,698
  • 14
  • 16
  • Ok...what do I need to change in my foo.wxs then? Anything? – George Mauer Aug 09 '16 at 20:14
  • Shouldn't need to change anything in foo.wxs. `` is allowed. I just think heat generating another dir with Name="SourceDir" is what light is complaining about. It might be that the dir with Name="SourceDir" **has** to be the root dir or the value of the TARGETDIR dir, not entirely sure. – Brian Sutherland Aug 09 '16 at 20:19
  • I renamed the directory to `foo/`, re-heated and candled `Dynamic.wxs`. Now `light` results in `W:\temp\Dynamic.wxs(7) : error LGHT0103 : The system cannot find the file 'SourceDir\bar.txt'.` `W:/temp/foo/bar.txt` definitely exists. – George Mauer Aug 09 '16 at 20:25
  • 2
    you might need "-var var.fooDir" in your heat cmd line then either pass "-d"fooDir=W:\temp\foo\"" to candle.exe or define define fooDir = W:\temp\foo\" ?> in your foo.wxs. -var will replace "SourceDir" with $(thevariable) in the heat generated Source tag. – Brian Sutherland Aug 09 '16 at 20:33
  • 1
    That worked! It installed to `Program Files (x86)\Dynamic` which is not what I expected bug I think I can figure it out from there. – George Mauer Aug 09 '16 at 20:43
  • Thank you very mush, this really help me a lot. – Jimmy Lin Mar 12 '18 at 08:57