如何使用 Wix 工具集的 HarvestDirectory?

How to use Wix Toolset's HarvestDirectory?

我想自动将文件夹 C:\example\dir 添加到 Wix 工具集 MSI 安装程序。

我这样使用 HarvestDirectory target

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
    <?include "Config.wxi" ?>
    <Product Id="*" Name="programName" Language="1033" Version="1.0.0.0" Manufacturer="Me" UpgradeCode="2275bf6b-489e-49f3-a7fd-cfd96ed94d7b">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" Platform="x64" />

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

        <Feature Id="ProductFeature" Title="programName" Level="1">
            <ComponentGroupRef Id="BinDirRefId" />
        </Feature>

        <UIRef Id="WixUI_InstallDir" />

        <Property Id="WIXUI_INSTALLDIR" Value="INSTALLFOLDER" />
    </Product>

    <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
            <Directory Id="ProgramFiles64Folder">
                <Directory Id="INSTALLFOLDER" Name="programName">
                    <Directory Id="BinDirRefId" Name="bin">
                    </Directory>
                </Directory>
            </Directory>
        </Directory>
    </Fragment>

    <ItemGroup>
        <HarvestDirectory Include="C:\example\dir">
            <DirectoryRefId>BinDirRefId</DirectoryRefId>
        </HarvestDirectory>
    </ItemGroup>
</Wix>

Visual Studio 告诉我 ItemGroup 不是 <Wix> 的有效子代。我应该如何正确使用这个目标?

像vcxproj 或csproj 一样,这些是MsBuild 的助手,需要将ItemGroup 添加到wixproj too to simplify the build. Then you can use the same Directory id as the example

根据您的尝试调整的相同代码段:

<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
  ...
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="foo.wxs" />
    <HarvestDirectory Include="C:\example\dir">
      <DirectoryRefId>BinDirRefId</DirectoryRefId>
      ...
    </HarvestDirectory>
    <WixExtension Include="WixUIExtension" />
  </ItemGroup>
  <Import Project="$(WixTargetsPath)" />
</Project>