65.9K
CodeProject 正在变化。 阅读更多。
Home

在 Wix 设置项目中启用 Harvest

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.10/5 (5投票s)

2016年6月21日

CPOL

2分钟阅读

viewsIcon

52972

downloadIcon

809

在 Wix 安装项目中启用 Harvest。

引言

本文将解释如何在 Wix 设置项目中启用和配置 Harvest。 这适用于 Wix 3.10 和 Visual Studio 2015。

Using the Code

让我们从在 Visual Studio 中创建一个新的解决方案开始。

接下来,让我们添加一个虚拟 ASP MVC 站点用于测试目的。

现在将一个 Wix 设置项目添加到您的解决方案中。

您的解决方案应该看起来像

好的,现在我们已经设置了初始项目。 让我们继续配置我们的 HeatDirectory 任务。 这需要我们修改 Visual Studio 使用的实际 Wix 设置项目文件。

首先,右键单击设置项目并选择“卸载”。

现在再次右键单击并选择“编辑”。

接下来,我们需要找到以下部分(通常位于文件的底部并被注释掉)

<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>

现在,我们想要配置我们的 HarvestDirectory 任务。 以下代码应该插入到上面的代码下方

<Target Name="BeforeBuild">
   <HeatDirectory 
      OutputFile="$(ProjectDir)\ProductInstallFiles.wxs" 
      Directory="..\Training.Wix.SampleSite" 
      ComponentGroupName="ProductFilesComponentGroup" 
      DirectoryRefId="INSTALLLOCATION" 
      AutogenerateGuids="true" 
      PreprocessorVariable="var.Training.Wix.SampleSite.ProjectDir" 
      SuppressRegistry="true" 
      SuppressRootDirectory="true" 
      ToolPath="$(WixToolPath)" 
      NoLogo="true" />
</Target>

所以让我们在重新加载项目之前稍微过一下代码。 Harvest 需要以下值才能正常工作。

OutputFile这是 Harvest 将保存其引用的文件的名称。
Directory(目录)要 Harvest 的目录。
DirectoryRefIdProduct.wxs 中的安装目录引用。
ComponentGroupName在 Product.wix 中用于安装文件的组件组名称。
Preprocessor 变量这必须采用 (var.HarvestProjectNameSpace.ProjectDir) 的格式。

Preprocessor 变量由 Candle 用于确定源文件所在的位置,以便可以安装它们。 它应该是您正在 Harvest 的应用程序的命名空间。 现在我们将重新加载我们的项目并开始设置我们的 product.wix

我将简要介绍 package.wix 文件及其初始设置。 首先,您需要在 product 元素上定义属性。 我已经将这些值抽象到单独的配置文件中。 它应该比下面的代码更简单。

<product id="*" 
    language="1033" 
    manufacturer="$(var.ProductManufacturer)" 
    name="$(var.ProductName)" 
    upgradecode="$(var.ProductUpgradeCode)" 
    version="$(var.ProductVersion)">
</product>

配置文件在 product.wix 文件的顶部导入,并具有以下设置

<!--?xml version="1.0" encoding="UTF-8"?-->
<!--?include ProductConfiguration.wxi ?-->
<!--?define ProductName = "My Custom Product" ?-->
<!--?define ProductManufacturer = "Manufacturer" ?-->
<!--?define ProductVersion = "1.0.0.1" ?-->  
<!--?define ProductUpgradeCode = "INSERT_NEW_GUID" ?-->

请确保使用新的 guid 更新产品升级代码。 现在,我们使用 feature 元素注册我们的 harvest 组件组。

<feature id="ProductFeature" level="1" title="HarvestSetup">
   <componentgroupref id="ProductFilesComponentGroup">
</componentgroupref></feature>

最后,告诉 wix 在哪里安装文件

<fragment>
   <directory id="TARGETDIR" name="SourceDir">
      <directory id="ProgramFilesFolder">
   <directory id="INSTALLLOCATION" name="HarvestSetup">
   <directory id="ProductFilesComponentGroup"></directory>
   </directory>
   </directory>
   </directory>
</fragment>

好的,现在我们已经设置了产品,让我们将一个引用添加到 Wix 设置项目到我们的测试应用程序。 这是来自 HarvestDirectory 任务的 processing 变量。 这允许我们在“ProductInstallFiles.wix”中访问“.ProjectDir”变量。

构建您的应用程序,您应该在输出窗口中看到对 heat.exe 的引用。 这是一个好迹象,如果没有,请尝试删除 references 文件夹并启用 harvest。

如果您看不到“ProductInstallFiles.wix”文件,那么它可能被从项目中排除。 简单地显示所有文件并包含在项目中。

完整的项目可以 从这里下载。

历史

  • 2016/06/21:初始帖子
© . All rights reserved.