2010-04-09 3 views
8

J'essaie de définir la variable du préprocesseur dans wix et je suis incapable de trouver un exemple ou une explication sur la façon de le faire n'importe où sur Internet, j'espère que quelqu'un ici peut expliquer ou me montrer où je vais mal!WIX HeatDirectory Tâche - Définition de la variable préprocesseur

J'ai essayé l'exemple montré ici en ce qui concerne les valeurs var cadre http://www.ageektrapped.com/blog/setting-properties-for-wix-in-msbuild/

La documentation pour l'utilisation des taks HeatDirectory à Wix peuvent être trouvés ici et n'est pas très utile du tout! Comment définir le paramètre preprocessorVariable pour substituer le SourceDir à un autre nom de variable?

+1

J'ai trouvé que c'était la réponse: http://stackoverflow.com/a/4280454/11421 –

Répondre

3

J'ai découvert ce que c'était, après 1 jour d'essayer différentes choses, le lien ci-dessus est correct mais pour utiliser le var dans la tâche répertoire, vous devez le faire comme ceci.

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

Il y a une propriété $(HeatDefinitions) vous pouvez définir les définir dans le dossier parent:

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

La seule mention existante de cette propriété magique que je peux trouver (sur tout l'Internet) est dans a single question about Team Build de la liste de diffusion wix-users. J'ai trébuché dessus par hasard après avoir passé près d'une journée à m'arracher les cheveux en essayant de corriger des erreurs variables de préprocesseur non définies.

+3

Si vous regardez l'extrait de wixproj dans cette publication, vous remarquerez un bit ' $ (HeatDefinitions) '... c'est là que se trouve la" magie ", il s'agit de splatter cette variable en une variable" réelle ". Il est séparé de cette façon afin qu'ils n'aient pas à se répéter pour le débogage ou la libération. – Cheetah

16

PréprocesseurVariable pour la chaleur a vraiment besoin de plus doc et exemple ... J'ai passé beaucoup de temps à le faire fonctionner aussi. Voici comment cela fonctionne dans mon fichier 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> 

Tout ce dont vous avez besoin est de définir la variable. Il n'y a pas de "HeatDefinitions" magiques :)

+5

C'est ce dont j'avais besoin! FWIW MS devrait vraiment mettre quelques ressources dans WiX, c'est un état de choses ridicule (la documentation). –

+2

Cela peut sembler évident à un expert (autre que moi): il faut définir cette variable var.HarvestPath dans le fichier * wixproj *. Il ne sera remplacé que plus tard lors de l'étape de pré-traitement du compilateur wix. Cela m'a pris plusieurs heures pour que cela fonctionne. –

0

J'ai un très grand kit d'installation à construire dans Visual Studio 2013 (inclut quelques outils liés au projet principal, un service Windows et une application web avec une structure de répertoire non trivial). J'apprends toujours à utiliser WiX et je continue d'élaborer, de tester et d'affiner le projet WiX. Actuellement, j'ai les tâches de récolte configurées en tant qu'événements de construction, en utilisant une commande de la forme

"C: \ Program Files (x86) \ Jeu d'outils WiX v3.9 \ bin \ heat.exe" dir "$) \ MyProjectDir \ bin \ $ (Nom_Configuration) "-cg MyComponentRef -ag -dr MYINSTALLDIR -srd -wixvar -var var.MySourceFiles -sreg -out" $ (SolutionDir) \ Déploiement \ Mon projet d'installation \ ComponentList.wxs "-t "$ (SolutionDir) \ Déploiement \ Mon programme d'installation \ FileFilter.xslt"

Cette commande récupère simplement tous les fichiers du dossier bin \ Debug (ou bin \ Release) du projet, puis les filtre à l'aide d'une transformation de feuille de style xml. Il y a quelques récoltes à rassembler comme ça, donc maintenir toutes les variables du fichier source (l'argument "var.MySourceFiles" dans la commande) devenait fastidieux et sujet aux erreurs. Initialement, j'avais ajouté les déclarations aux variables du préprocesseur du projet, mais je voulais quelque chose qui soit un peu plus «autonome». En utilisant les conseils utiles que j'ai trouvé à WiX tricks and tips, je déclarai un nouveau fichier à inclure, « PreprocessorVars.wxi » avec un contenu

et a obtenu le xslt pour l'inclure dans la sortie générée par la chaleur.exe avec l'extrait

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

xslt produit maintenant sortie qui ressemble à ceci:

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

qui traite Wix sans aucune erreur.

7

J'utilise Wix v3.10.

Inutile d'appeler explicitement la tâche MSBuild de HeatDirectory. ItemGroup avec le nom spécial "HarvestDirectory" peut être préparé, et plus tard la cible "HarvestDirectory" le traitera. * Le fichier .wsx est créé dans IntermediateOutputPath et est inclus dans la liste de compilation (traitée par 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> 

Le fichier wxs:

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

Merci pour ça. J'ai passé une demi-journée à essayer de créer une configuration pour une sortie publiée d'un site Asp.NET Core. On pourrait penser que quelque chose d'aussi commun serait bien documenté sur internet. La vôtre est la première réponse qui a réellement fonctionné. – Eternal21

+1

Heureux que ça a marché pour vous. Il semble que MSBuild et WIX n'ont pas beaucoup changé et fonctionnent encore même pour le projet ASP.NET Core. –

3

J'ai créé un exemple sur GitHub montrant comment utiliser avec succès le HarvestDirectory target, ce qui est une chose de plus haut niveau qui appelle la tâche HeatDirectory. Vous n'avez pas besoin d'appeler directement la tâche HeatDirectory vous-même. Vous pouvez voir tout le code exemple ici:

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

Voici les parties les plus importantes:

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

Merci d'inclure le fichier wxs. –

Questions connexes