2010-04-09 59 views
8

我想設置wix中的預處理器變量,我無法找到這個例子或解釋如何在互聯網上的任何地方做到這一點,我希望有人在這裏可以解釋或告訴我哪裏會出錯!WIX HeatDirectory任務 - 設置預處理器變量

我試圖關於設置VAR圖示例值 http://www.ageektrapped.com/blog/setting-properties-for-wix-in-msbuild/

的文檔使用HeatDirectory TAKS在威克斯可以在這裏找到,是不是非常有用了!

如何設置預處理器變量來替換SourceDir的另一個變量名?

+1

我發現這是答案:http://stackoverflow.com/a/4280454/11421 – 2012-05-12 04:58:18

回答

3

我發現它是什麼,在嘗試了各種事情1天后,上面的鏈接是正確的,但要在熱目錄任務中使用var,您必須這樣做。

<HarvestDirectory Include="$(ProjectDirectory)\" > 
     <DirectoryRefId>WEBDIR</DirectoryRefId> 
     <KeepEmptyDirectories>true</KeepEmptyDirectories> 
     <SuppressRegistry>true</SuppressRegistry> 
     <ComponentGroupName>DynamicWebFiles</ComponentGroupName> 
     <PreprocessorVariable>var.WixDynamicSourceDirectory</PreprocessorVariable> 
    </HarvestDirectory> 
3

有一個$(HeatDefinitions)屬性,你可以設置在父.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> 

這個神奇的財產,我可以找到(整個互聯網上)的現有唯一一提的是在wix-users郵件列表中的a single question about Team Build。我花了將近一天的時間,試圖修復未定義的預處理器變量錯誤後,我偶然發現了這個問題。

+3

如果你看看該郵件列表文章中的wixproj片段,你會注意到' $(HeatDefinitions)'...這就是「魔法」的地方,它將這個變量噴濺到一個「真正的」變量中。它是這樣分開的,所以他們不必爲調試與發佈而重複自己。 – Cheetah 2012-03-26 23:36:16

16

預處理器變熱的真正需要更多的文檔和示例...我花了很多時間使它工作。這是它在我的wixproj文件中的工作原理:

<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> 

所有你需要的是定義變量。沒有神奇的「HeatDefinitions」:)

+5

這就是我需要的! FWIW MS應該真的把一些資源投入到WiX上,這是一個荒謬的事態(文檔)。 – 2013-02-16 19:24:51

+2

對於專家(我比其他人)來說可能很明顯:必須將var.HarvestPath變量定義到* wixproj *文件。它將在稍後的wix編譯器的預處理步驟中被替換。花了我幾個小時纔得到這個工作。 – 2014-05-28 15:46:58

0

我有一個非常大的安裝程序工具包來構建Visual Studio 2013(包括一些與主項目相關的工具,Windows服務和具有非平凡目錄結構的Web應用程序)。我仍然在學習如何使用WiX,並且仍在制定,測試和改進WiX項目。目前,我使用格式爲

「C:\ Program Files(x86)\ WiX Toolset v3.9 \ bin \ heat.exe」dir「$(SolutionDir)的命令將收穫任務設置爲構建事件)\ MyProjectDir \ bin \ $(ConfigurationName)「-cg MyComponentRef -ag -dr MYINSTALLDIR -srd -wixvar -var 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」參數)變得單調乏味且容易出錯。最初,我已經將這些聲明添加到項目的預處理器變量中,但我想要一些更「自包含」的東西。使用有用的提示,我發現在WiX tricks and tips,我宣佈一個新的包含文件,「PreprocessorVars.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> 

其維克斯處理沒有任何錯誤:與片段

<xsl:processing-instruction name="include"> 
     $(sys.CURRENTDIR)\PreprocessorVars.wxi 
    </xsl:processing-instruction> 

的XSLT現在產生的輸出看起來像這樣的EXE。

7

我使用Wix v3.10。

不需要顯式調用HeatDirectory MSBuild任務。可以準備特殊名稱爲「HarvestDirectory」的ItemGroup,稍後「HarvestDirectory」目標將處理它。 * .wsx文件在IntermediateOutputPath中創建,幷包含在編譯列表中(由Candle處理)。

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' "> 
... 
    <MyFinalFolder Condition=" '$(MyFinalFolder)' == '' ">$(MSBuildProjectDirectory)\Final\</MyFinalFolder> 
    <DefineConstants>FinalFolder=$(MyFinalFolder)</DefineConstants> 
</PropertyGroup> 

... 

<Import Project="$(WixTargetsPath)" /> 
<Target Name="BeforeBuild"> 
    <!-- 
    No need to explicitly call HeatDirectory MSBuild Task. 
    Instead follow documentation http://wixtoolset.org/documentation/manual/v3/msbuild/target_reference/harvestdirectory.html, which has sample and 
    important comment: 
    This target is processed before compilation. Generated authoring is automatically added to the Compile item group to be compiled by the Candle task. 
    So, *.wsx file created in the IntermediateOutputPath and included in Compile list (processed by Candle). 

    The following ItemGroup with special name "HarvestDirectory" can be prepared, and later the "HarvestDirectory" target will process it, see 
    C:\Program Files (x86)\MSBuild\Microsoft\WiX\v3.x\wix2010.targets 
    --> 
    <ItemGroup> 
    <HarvestDirectory Include="$(MyFinalFolder)"> 
     <DirectoryRefId>INSTALLFOLDER</DirectoryRefId> 
     <SuppressRootDirectory>true</SuppressRootDirectory> 
     <SuppressCom>true</SuppressCom> 
     <SuppressRegistry>true</SuppressRegistry> 
     <ComponentGroupName>FilesComponentGroup</ComponentGroupName> 
     <PreprocessorVariable>var.FinalFolder</PreprocessorVariable> 
    </HarvestDirectory> 
    </ItemGroup> 
</Target> 

的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> 
+1

非常感謝。花了半天的時間嘗試創建一個Asp.NET Core網站已發佈輸出的設置。你會認爲這樣常見的東西會在互聯網上得到很好的記錄。你是第一個真正有效的答案。 – Eternal21 2017-10-19 20:28:24

+1

很高興爲你效勞。看起來MSBuild和WIX並沒有太大的改變,即使對於ASP.NET Core項目也仍然有效。 – 2017-10-20 14:24:49

3

我創建GitHub上的示例項目展示瞭如何成功地使用HarvestDirectory target,這是調用HeatDirectory任務更高級的東西。您不需要自己直接調用HeatDirectory任務。你可以看到所有的示例代碼瀏覽:

https://github.com/DavidEGrayson/wix-example-harvest-directory

這裏是最重要的部分:

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> 

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> 
+0

感謝您包含wxs文件。 – 2016-08-16 08:40:12