Msbuild WIX HeatDirectory任务-设置预处理器变量
我正试图在wix中设置预处理器变量,但我在互联网上找不到这样的例子或解释,我希望这里的人能解释或告诉我哪里出了问题 我已经尝试了这里显示的关于设置var值的示例 在wix中使用HeatDirectory-taks的文档可以在这里找到,它一点用处都没有Msbuild WIX HeatDirectory任务-设置预处理器变量,msbuild,wix,Msbuild,Wix,我正试图在wix中设置预处理器变量,但我在互联网上找不到这样的例子或解释,我希望这里的人能解释或告诉我哪里出了问题 我已经尝试了这里显示的关于设置var值的示例 在wix中使用HeatDirectory-taks的文档可以在这里找到,它一点用处都没有 如何设置预处理器变量以将SourceDir替换为另一个变量名?我发现了它是什么,经过一天的尝试,上面的链接是正确的,但要在heatdirectory任务中使用var,您必须这样做 <HarvestDirectory Include="$(P
如何设置预处理器变量以将SourceDir替换为另一个变量名?我发现了它是什么,经过一天的尝试,上面的链接是正确的,但要在heatdirectory任务中使用var,您必须这样做
<HarvestDirectory Include="$(ProjectDirectory)\" >
<DirectoryRefId>WEBDIR</DirectoryRefId>
<KeepEmptyDirectories>true</KeepEmptyDirectories>
<SuppressRegistry>true</SuppressRegistry>
<ComponentGroupName>DynamicWebFiles</ComponentGroupName>
<PreprocessorVariable>var.WixDynamicSourceDirectory</PreprocessorVariable>
</HarvestDirectory>
WEBDIR
真的
真的
动态Web文件
var.WixDynamicSourceDirectory
有一个$(HeatDefinitions)
属性,您可以在parent.wixproj文件中设置它来定义这些属性:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<HeatDefinitions>MySourcePath=..\src\Your.App\bin\Release</HeatDefinitions>
</PropertyGroup>
<ItemGroup>
<Compile Include="Phoenix.wxs" />
<Compile Include="_HeatGeneratedFileList.wxs" />
</ItemGroup>
<Target Name="BeforeBuild">
<HeatDirectory Directory="..\src\Your.App\bin\Release"
OutputFile="_HeatGeneratedFileList.wxs"
PreprocessorVariable="var.MySourcePath" />
</Target>
</Project>
<PropertyGroup>
<DefineConstants Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">HarvestPath=..\distribution\Debug</DefineConstants>
<DefineConstants Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">HarvestPath=..\distribution\Release</DefineConstants>
</PropertyGroup>
<Target Name="BeforeBuild">
<HeatDirectory Directory="..\distribution\$(Configuration)"
PreprocessorVariable="var.HarvestPath"
OutputFile="HeatGeneratedFileList.wxs"
ComponentGroupName="HeatGenerated"
DirectoryRefId="INSTALLFOLDER"
AutogenerateGuids="true"
ToolPath="$(WixToolPath)"
SuppressFragments="true"
SuppressRegistry="true"
SuppressRootDirectory="true"/>
</Target>
MySourcePath=..\src\Your.App\bin\Release
我(在整个互联网上)能找到的关于这个神奇财产的唯一提及是在wix用户邮件列表中。我花了将近一天的时间试图修复未定义的预处理器变量错误,但不幸地发现了它。用于加热的预处理器变量确实需要更多的文档和示例。。。我也花了很多时间让它工作。以下是它在我的wixproj文件中的工作方式:
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<HeatDefinitions>MySourcePath=..\src\Your.App\bin\Release</HeatDefinitions>
</PropertyGroup>
<ItemGroup>
<Compile Include="Phoenix.wxs" />
<Compile Include="_HeatGeneratedFileList.wxs" />
</ItemGroup>
<Target Name="BeforeBuild">
<HeatDirectory Directory="..\src\Your.App\bin\Release"
OutputFile="_HeatGeneratedFileList.wxs"
PreprocessorVariable="var.MySourcePath" />
</Target>
</Project>
<PropertyGroup>
<DefineConstants Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">HarvestPath=..\distribution\Debug</DefineConstants>
<DefineConstants Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">HarvestPath=..\distribution\Release</DefineConstants>
</PropertyGroup>
<Target Name="BeforeBuild">
<HeatDirectory Directory="..\distribution\$(Configuration)"
PreprocessorVariable="var.HarvestPath"
OutputFile="HeatGeneratedFileList.wxs"
ComponentGroupName="HeatGenerated"
DirectoryRefId="INSTALLFOLDER"
AutogenerateGuids="true"
ToolPath="$(WixToolPath)"
SuppressFragments="true"
SuppressRegistry="true"
SuppressRootDirectory="true"/>
</Target>
HarvestPath=…\distribution\Debug
HarvestPath=…\distribution\Release
您只需要定义变量。没有神奇的“热定义”:我有一个非常大的安装工具包要在Visual Studio 2013中构建(包括一些与主项目相关的工具、一个windows服务和一个具有非平凡目录结构的web应用程序)。我仍在学习如何使用WiX,并且仍在制作、测试和完善WiX项目。目前,我使用表单的命令将收获任务设置为构建事件 “C:\Program Files(x86)\WiX工具集v3.9\bin\heat.exe”dir“$(SolutionDir)\MyProjectDir\bin\$(ConfigurationName)”-cg MyComponentRef-ag-dr MYINSTALLDIR-srd-wixvar-var.MySourceFiles-sreg-out“$(SolutionDir)\Deployment\My Installer Project\ComponentList.wxs”-t“$(SolutionDir)\Deployment\My Installer Project\FileFilter.xslt” 此命令只获取项目的bin\Debug(或bin\Release)文件夹中的所有文件,然后使用xml样式表转换对其进行过滤。有相当多的收获是这样收集的,因此维护所有源文件变量(命令中的“var.MySourceFiles”参数)变得单调乏味且容易出错。最初,我已经将声明添加到项目的预处理器变量中,但我想要一些更“自包含”的东西。使用在中找到的有用提示,我声明了一个新的包含文件“PreprocessorVars.wxi”,其中包含内容 并让xslt将其包含在heat.exe生成的输出中
<xsl:processing-instruction name="include">
$(sys.CURRENTDIR)\PreprocessorVars.wxi
</xsl:processing-instruction>
$(sys.CURRENTDIR)\preprocessvars.wxi
xslt现在生成如下输出:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:wix="http://schemas.microsoft.com/wix/2006/wi">
<?include
$(sys.CURRENTDIR)\PreprocessorVars.wxi
?>
<Fragment>
<DirectoryRef Id="MYINSTALLDIR" />
</Fragment>
<Fragment>
<ComponentGroup Id="MyComponentRef">
<Component Id="xyz" Directory="MYINSTALLDIR" Guid="*">
<File Id="abc" KeyPath="yes" Source="$(var.MySourceFiles)\MyProjectExecutable.exe" />
</Component>
</ComponentGroup>
</Fragment>
</Wix>
哪些Wix进程没有任何错误。我使用wixv3.10
无需显式调用HeatDirectory MSBuild任务。可以准备具有特殊名称“HarvestDirectory”的ItemGroup,稍后“HarvestDirectory”目标将对其进行处理。*。wsx文件在IntermediateOutput路径中创建,并包含在编译列表中(由Candle处理)
...
$(MSBuildProjectDirectory)\Final\
FinalFolder=$(MyFinalFolder)
...
安装文件夹
真的
真的
真的
文件组件组
var.FinalFolder
wxs文件:
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Fragment>
<DirectoryRef Id="INSTALLFOLDER">
<Component Id="cmp9AA09F4A73FA53E2BDDE4B7BB5C91DFB" Guid="*">
<File Id="fil9AA09F4A73FA53E2BDDE4B7BB5C91DFB" KeyPath="yes" Source="$(var.FinalFolder)\7z.dll" />
</Component>
我在GitHub上创建了一个示例项目,展示了如何成功使用,这是一个调用HeatDirectory任务的更高级别的东西。您不需要自己直接调用HeatDirectory任务。您可以在此处看到所有示例代码: 以下是最重要的部分: foo.wixproj
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProductVersion>1.0.0</ProductVersion>
<DefineConstants>ProductVersion=$(ProductVersion);ItemDir=items</DefineConstants>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>27e80d9b-d8b6-423a-a6ff-1d9c5b23bb31</ProjectGuid>
<SchemaVersion>2.0</SchemaVersion>
<OutputName>foo-$(ProductVersion)</OutputName>
<OutputType>Package</OutputType>
<DefineSolutionProperties>false</DefineSolutionProperties>
<WixTargetsPath Condition=" '$(WixTargetsPath)' == '' ">$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets</WixTargetsPath>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Debug;ProductVersion=$(ProductVersion)</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
</PropertyGroup>
<ItemGroup>
<Compile Include="foo.wxs" />
<HarvestDirectory Include="items">
<DirectoryRefId>ItemDir</DirectoryRefId>
<ComponentGroupName>Items</ComponentGroupName>
<PreprocessorVariable>var.ItemDir</PreprocessorVariable>
</HarvestDirectory>
<WixExtension Include="WixUIExtension" />
</ItemGroup>
<Import Project="$(WixTargetsPath)" />
</Project>
1.0.0
ProductVersion=$(ProductVersion);ItemDir=项目
调试
x86
27e80d9b-d8b6-423a-a6ff-1d9c5b23bb31
2
foo-$(产品版本)
包裹
假的
$(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\WiX.targets
bin\$(配置)\
obj\$(配置)\
调试;ProductVersion=$(ProductVersion)
bin\$(配置)\
obj\$(配置)\
ItemDir
项目
变量ItemDir
foo.wxs
<?xml version="1.0" encoding="utf-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Name="Foo"
Version="$(var.ProductVersion)"
Manufacturer="Foo Inc."
Language="1033"
UpgradeCode="0c8504c9-4e62-4e2c-9e1c-4fbe1c478b37"
Id="*">
<Package Description="Foo"
Manufacturer="Foo Inc."
Compressed="yes"
InstallerVersion="301" />
<MajorUpgrade AllowDowngrades="no"
DowngradeErrorMessage="A newer version of this software is already installed."
AllowSameVersionUpgrades="no" />
<Media Id="1" Cabinet="cabinet.cab" EmbedCab="yes" />
<Property Id="ARPCOMMENTS">
Foo package.
</Property>
<Property Id="ARPCONTACT">Foo Inc.</Property>
<Property Id="ARPURLINFOABOUT">https://www.example.com/</Property>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder" Name="PFiles">
<Directory Id="INSTALLDIR" Name="Foo">
<Component Id="readme">
<File Id="readme" Name="README.txt" Source="README.txt" />
</Component>
<Directory Id="ItemDir" />
</Directory>
</Directory>
</Directory>
<Feature Id="Software"
Title="Foo"
AllowAdvertise="no"
ConfigurableDirectory="INSTALLDIR">
<ComponentRef Id="readme" />
<ComponentGroupRef Id="Items" />
</Feature>
<Property Id="WIXUI_INSTALLDIR" Value="INSTALLDIR" />
<UIRef Id="WixUI_InstallDir" />
</Product>
</Wix>
Foo包。
福公司。
https://www.example.com/
如果您查看邮件列表帖子中的wixproj代码片段,您会注意到一点$(热定义)
。。。这就是“魔力”所在,它是将变量分解成一个“真实”变量。它是这样分开的,这样他们就不必在调试和发布时重复自己了。我发现这就是答案:这就是我所需要的!FWIW MS真的应该在WiX中投入一些资源,这是一种荒谬的状态(文档)。对于专家(我以外的人)来说,这可能是显而易见的:必须将var.HarvestPath变量定义到wixproj文件中。它将仅在稍后wix编译器的预处理步骤中被替换。我花了几个小时才让它工作。所以HeatDirectory的Directory属性似乎不可能使用任何类型的变量作为路径?我