0

I'm following this tutorial to create a WiX installer for a VS2017 Winform app. It's just a default Winform app (nothing fancy). But when I build the WiX project (SetupProject1 shown in figure 1 below), I get the following error at first <File id=.../> tag of ProductComponent.wxs (shown below).

Question: What I may be missing here?

Note: I'm using this Wix Toolset Visual Studio 2017 Extension

Error:

Undefined preprocessor variable '$(var.SetupProject1.TargetDir)'

VS2017 Solution Explorer:

enter image description here

Product.wxs

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Product Id="89ae9543-fdf1-444b-9678-811483fd58bd" Name="SetupProject1" Language="1033" Version="1.0.0.0" Manufacturer="WiX_test_4_Winfrm" UpgradeCode="e69fe67b-5c28-4764-8196-a6613b840eff">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <UIRef Id="WixUI_Mondo" />
    <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER"></Property>

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate EmbedCab="yes" />

        <Feature Id="ProductFeature" Title="SetupProject1" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFilesFolder">
                <Directory Id="INSTALLFOLDER" Name="SetupProject1" />
            </Directory>
        </Directory>
    </Fragment>

    <Fragment>
        <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
            <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
             <Component Id="CMP_SetupProject1">
         <File Source="$(var.WIX_WinfrmTest.TargetPath)" />
             </Component> 
        </ComponentGroup>
    </Fragment>
</Wix>

ProductComponent.wxs

<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <Fragment>
        <DirectoryRef Id="INSTALLFOLDER" />
    </Fragment>
    <Fragment>
        <ComponentGroup Id="ProductComponents">
            <Component Id="cmp2C5CB3BF0E009CA9CF5E03CADA38250D" Directory="INSTALLFOLDER" Guid="{C694E446-7B01-42C0-9056-4E09834809E9}">
                <File Id="fil3A244EF6571347120C494BB170DC368E" KeyPath="yes" Source="$(var.SetupProject1.TargetDir)\cab1.cab" />
            </Component>
            <Component Id="cmpB6E89A2030E867C94B57A39FE26E1181" Directory="INSTALLFOLDER" Guid="{E8E1247F-627F-420D-97E0-0ABE39A2064C}">
                <File Id="fil41A028F0E06C7EEE038806BDA5979087" KeyPath="yes" Source="$(var.SetupProject1.TargetDir)\SetupProject1.msi" />
            </Component>
            <Component Id="cmpD2FFED031AA728C90BED6090228F3AE3" Directory="INSTALLFOLDER" Guid="{660414BB-E061-4EE2-A7E2-471EA41C031F}">
                <File Id="fil3F7C931DA08579E26A8F50778E59444A" KeyPath="yes" Source="$(var.SetupProject1.TargetDir)\SetupProject1.wixpdb" />
            </Component>
        </ComponentGroup>
    </Fragment>
</Wix>
nam
  • 21,967
  • 37
  • 158
  • 332
  • 1
    Received your comment, I believe @smilinger below has the correct solution. You don't need ProductComponents.wxs file removing it will likely resolve the error. The ProductComponents.wxs contains references to the output of your install project, in other words it contains references to files that don't exist yet, SetupProject1.msi would be the result of the SetupProject.wixproj, this won't work. – Rick Bowerman Dec 28 '17 at 14:56
  • @RickBowerman Your suggestion worked (thank you) and hence I've marked the response from `@smilinger` as an answer. But I was wondering why then [this article](http://www.paulsodimu.co.uk/Post/How-To-Create-a-Wix-Installer-For-a-Console-Application) - that I was following is using - is using the external tool to create `ProductComponents.wxs`? Because the the topic of the article is `HOW TO CREATE A WIX INSTALLER FOR A CONSOLE APPLICATION` and I noticed (after your suggestion) that the installer could be created without using Eternal Tools and `ProductComponents.wxs` part of the article posted – nam Dec 28 '17 at 17:41

1 Answers1

1

Just remove your second file ProductComponent.wxs should be OK.

The external tool mentioned on that blog is a good idea, but that should only be run by activating your winform project not your current project (the wix project).

smilinger
  • 63
  • 6