C# WiX-未定义的预处理器变量“$(var.SetupProject1.TargetDir)”

C# WiX-未定义的预处理器变量“$(var.SetupProject1.TargetDir)”,c#,winforms,wix,C#,Winforms,Wix,下面我将为VS2017 Winform应用程序创建一个WiX安装程序。这只是一个默认的Winform应用程序,没什么特别的。但是,当我构建下图1中所示的WiX项目SetupProject1时,我在ProductComponent.wxs的第一个标记处出现以下错误,如下所示 问题:我在这里可能缺少什么 注意:我正在使用这个 错误: 未定义的预处理器变量“$var.SetupProject1.TargetDir” VS2017解决方案资源管理器: Product.wxs ProductCompone

下面我将为VS2017 Winform应用程序创建一个WiX安装程序。这只是一个默认的Winform应用程序,没什么特别的。但是,当我构建下图1中所示的WiX项目SetupProject1时,我在ProductComponent.wxs的第一个标记处出现以下错误,如下所示

问题:我在这里可能缺少什么

注意:我正在使用这个

错误:

未定义的预处理器变量“$var.SetupProject1.TargetDir”

VS2017解决方案资源管理器:

Product.wxs

ProductComponent.wxs


只需删除第二个文件ProductComponent.wxs就可以了


该博客中提到的外部工具是一个好主意,但只能通过激活winform项目而不是当前项目wix项目来运行该工具。

收到您的评论,我相信下面的@smilinger有正确的解决方案。您不需要ProductComponents.wxs文件。删除它可能会解决此错误。ProductComponents.wxs包含对安装项目输出的引用,换句话说,它包含对尚不存在的文件的引用,SetupProject1.msi将是SetupProject.wixproj的结果,这将不起作用。@RickBowerman您的建议奏效了谢谢,因此我将@smilinger的响应标记为答案。但我想知道,为什么我接下来使用的是外部工具来创建ProductComponents.wxs?因为这篇文章的主题是如何为控制台应用程序创建WIX安装程序,我注意到在你建议创建安装程序时不需要使用永恒的工具和ProductComponents.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>
<?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>