[wix-users] Pointing Heat at Referenced Project Output Folder

Bryan Dam bryand at recastsoftware.com
Thu Dec 16 14:07:02 PST 2021


Thanks Luca and Zac!

> It looks like both of you are mixing msbuild syntax with WiX syntax
Totally, 100%.  I felt it but didn't know where one ended and the other began but your answers helped me sort it out.

What particularly clicked is that Heat generates the WXS files and itself can't use the project reference properties (ex. var.ProjectName.TargetDir).  That's what your bit of MSBuild magic there does: gets that referenced project's target directory before running Heat without actually building said project.  When heat runs it harvests that directory and swaps in the PreprocessorVariable string value exactly as-is for the source directory. In my case I can then use var.AgentGateway.TargetDir so that when the MSI builds WiX swaps in the right path because it's generated the referenced project preprocessor variable.  It feels kinda weird having to get the same path two different ways but ... ok ... I think I understand why.

My next task is to add a publish step for a couple of web projects before the harvest but I think I have an idea on making that happen. 
  Thanks again everyone,
         Bryan

-----Original Message-----
From: wix-users <wix-users-bounces at lists.wixtoolset.org> On Behalf Of Davidsen, Zac (Zachary) T via wix-users
Sent: Thursday, December 16, 2021 10:03 AM
To: WiX Toolset Users Mailing List <wix-users at lists.wixtoolset.org>
Cc: Davidsen, Zac (Zachary) T <ZTDAVIDSEN at beckman.com>
Subject: Re: [wix-users] Pointing Heat at Referenced Project Output Folder

It looks like both of you are mixing msbuild syntax with WiX syntax, which is probably part of why things aren't working the way you expect them to.

The $(var.<ProjectName>.<Property>) variables are only accessible in wix source files, and I'm honestly not sure what all it does behind the scenes to construct those.  If you want to use them in the .wixproj file you'll have to either find how wix creates those, or come up with your own version for getting that information.

I think you can get somewhat close to what you're aiming for with something like this:

<!-- We set this to run around BeforeBuild, because the HarvestDirectory item needs to be created before WiX tries to consume it during the build --> <Target Name="GetProjectOutputs" AfterTargets="BeforeBuild">
        <!-- Ask MSBuild to tell us where it's going to put the "main" output (.exe or .dll) of the  referenced project -->
        <MSBuild
                Projects="..\Product.AgentGateway\Product.AgentGateway.csproj "
                Targets="GetTargetPath"
                Properties="Configuration=$(Configuration);Platform=$(Platform)"> <!-- Note that this line in particular is very setup dependent and you may need to modify it to hardcode values and/or add additional properties -->
                <Output TaskParameter="TargetOutputs" ItemName="ProjectOutputPath" />
        </MSBuild>
        <PropertyGroup>
                <!-- Use some msbuild property function magic to get the directory name -->
                <GatewayFolder>$([System.IO.Path]::GetDirectoryName(%(ProjectOutputPath.Identity)))</GatewayFolder>
                <!-- Note the single quotes around the GatewayFolder in DefineConstants, you'll need those if there are embedded spaces -->
                <DefineConstants>$(DefineConstants);'GatewayFolder=$(GatewayFolder)';</DefineConstants>
        </PropertyGroup>
        <ItemGroup>
                <HarvestDirectory Include="$(GatewayFolder)">
                        <DirectoryRefId>INSTALLFOLDER</DirectoryRefId>
                        <PreprocessorVariable>var.GatewayFolder</PreprocessorVariable>
                        < ComponentGroupName>...</ ComponentGroupName>
                        ...
                </HarvestDirectory>
        </ItemGroup>
</Target>

I haven't tested this, but I have some vaguely similar msbuild code that I've written before, so I don't think it should be too far off from working.  It's probably worth a longer look at the msbuild reference docs in general, since this is getting somewhat specialized and technical.

Some references, in no particular order:
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwixtoolset.org%2Fdocumentation%2Fmanual%2Fv3%2Fmsbuild%2Ftarget_reference%2Fharvestdirectory.html&data=04%7C01%7Cbryand%40recastsoftware.com%7C9b6ce5011e914523975a08d9c0a534be%7C9315bb44634846c6bd378880b87e774e%7C0%7C0%7C637752638249861805%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=XS0zIErcEMbuU9LiQXOm%2FEjHq2hrfZq7hB4%2B8ZrJmu0%3D&reserved=0
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fvisualstudio%2Fmsbuild%2Fmsbuild-task%3Fview%3Dvs-2022&data=04%7C01%7Cbryand%40recastsoftware.com%7C9b6ce5011e914523975a08d9c0a534be%7C9315bb44634846c6bd378880b87e774e%7C0%7C0%7C637752638249871795%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=uanmn161uKFUsAWzsTqWjRagbRfMu6Zrdc%2BVU2Mqbyc%3D&reserved=0
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fvisualstudio%2Fmsbuild%2Fproperty-functions%3Fview%3Dvs-2022&data=04%7C01%7Cbryand%40recastsoftware.com%7C9b6ce5011e914523975a08d9c0a534be%7C9315bb44634846c6bd378880b87e774e%7C0%7C0%7C637752638249871795%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=vDUimBgQEfJke3tmkCh9LzF%2Fk01IbBGJJeY0q2Dck%2FY%3D&reserved=0

Zac

-----Original Message-----
From: wix-users <wix-users-bounces at lists.wixtoolset.org> On Behalf Of Luca Bacci via wix-users
Sent: Wednesday, December 15, 2021 4:18 PM
To: WiX Toolset Users Mailing List <wix-users at lists.wixtoolset.org>
Cc: Luca Bacci <luca.bacci982 at gmail.com>
Subject: Re: [wix-users] Pointing Heat at Referenced Project Output Folder

Here's the documentation:
https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.proofpoint.com%2Fv2%2Furl%3Fu%3Dhttps-3A__wixtoolset.org_documentation_manual_v3_msbuild_target-5Freference_harvestdirectory.html%26d%3DDwICAg%26c%3D9mghv0deYPYDGP-W745IEdQLV1kHpn4XJRvR6xMRXtA%26r%3DHblpuym5RtUs_4R6qwcviv7o1-X2VNe9YBkPtiuw4mw%26m%3Dwzc8yvqs-GaSbHQtVMZifumBjrvabG00EdhUMnMJ_kxjLhmnXuzapfBYyNntZkx6%26s%3D2JDJfDaT39lc5XW13pBTCqJWc-rgDqmKWH9GH_CrYG0%26e%3D&data=04%7C01%7Cbryand%40recastsoftware.com%7C9b6ce5011e914523975a08d9c0a534be%7C9315bb44634846c6bd378880b87e774e%7C0%7C0%7C637752638249871795%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=E62cg1e0H5mE1XRH7MkOzN1C3jOn%2F6enq4B93i1WjUM%3D&reserved=0

Regarding the first snippet, I think you should be using a $ character, not %. So it becomes:

<PropertyGroup>
                <DefineConstants>GatewayFolder=$ (var.ProductAgentGateway.
TargetDir)</DefineConstants>
</PropertyGroup>

Anyway you don't need that at all! Wix already gives you the TargetDir (and also other properties) of all referenced projects. See https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.proofpoint.com%2Fv2%2Furl%3Fu%3Dhttps-3A__wixtoolset.org_documentation_manual_v3_votive_votive-5Fproject-5Freferences.html%26d%3DDwICAg%26c%3D9mghv0deYPYDGP-W745IEdQLV1kHpn4XJRvR6xMRXtA%26r%3DHblpuym5RtUs_4R6qwcviv7o1-X2VNe9YBkPtiuw4mw%26m%3Dwzc8yvqs-GaSbHQtVMZifumBjrvabG00EdhUMnMJ_kxjLhmnXuzapfBYyNntZkx6%26s%3DQHARK3l_umWSAyymuNshixl9nETsZ60_gzhFm8br5DQ%26e%3D&data=04%7C01%7Cbryand%40recastsoftware.com%7C9b6ce5011e914523975a08d9c0a534be%7C9315bb44634846c6bd378880b87e774e%7C0%7C0%7C637752638249871795%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=aAKYNvqh16WaduU2PABJE4YWTS7NT7tqsuM6fN8kVL0%3D&reserved=0

So the first snippet can be removed.

The second snippet about the Project reference looks ok to me.

As for the third snippet, I think it's wrong. You should not put a HeatDirectory inside a Target. So delete it altogether. What you have to do is define a ItemGroup with HarvestDirectory items inside:

<Project
...
<ItemGroup Label="HarvestDirs">
    <HarvestDirectory  Include="$(GatewayFolder)">
      <DirectoryRefId>INSTALLFOLDER</DirectoryRefId>
      <ComponentGroupName>ProductAgentGateway</ComponentGroupName>
      <SuppressCom>True</SuppressCom>
      <SuppressRegistry>True</SuppressRegistry>
      <!--
      <KeepEmptyDirectories>True</KeepEmptyDirectories>
      -->
      <SuppressRootDirectory>True</SuppressRootDirectory>
      <PreprocessorVariable>var.GatewayFolder</PreprocessorVariable>
    </HarvestDirectory>
  </ItemGroup>
...
</Project>

A wxs file will be automatically generated during the build process and included for compilation.

Question: how is the GatewayFolder property defined? Note that you might have to define it as a relative path due to an issue in Wix, see https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.proofpoint.com%2Fv2%2Furl%3Fu%3Dhttps-3A__github.com_wixtoolset_issues_issues_4493%26d%3DDwICAg%26c%3D9mghv0deYPYDGP-W745IEdQLV1kHpn4XJRvR6xMRXtA%26r%3DHblpuym5RtUs_4R6qwcviv7o1-X2VNe9YBkPtiuw4mw%26m%3Dwzc8yvqs-GaSbHQtVMZifumBjrvabG00EdhUMnMJ_kxjLhmnXuzapfBYyNntZkx6%26s%3Dr0ichRxHPoZo9uWL6YbR_WJ56ta_7mG-TyUHdo4ZGoc%26e%3D&data=04%7C01%7Cbryand%40recastsoftware.com%7C9b6ce5011e914523975a08d9c0a534be%7C9315bb44634846c6bd378880b87e774e%7C0%7C0%7C637752638249871795%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=7QE7vNNcJhiCmV44ztsFKz%2FhUr79deFSYldinV9%2B57Y%3D&reserved=0


Il mer 15 dic 2021, 20:27 Bryan Dam via wix-users < wix-users at lists.wixtoolset.org> ha scritto:

> We're reorganizing our code in a way that put the Wix 3.11 
> installation projects in the same solution as the project we want it 
> to install.  We already use Heat but it's pointed it at what I call 
> 'magic folders' where the build pipeline had to put together the 
> binaries into that magic folder by downloading them different 
> pipelines.  I've been reading and trying different tactics for a couple of days but nothing seems to work.
>
> I've avoided using HeatProject since avoiding it seems to be the 
> widely accepted suggestion, by Rob himself.  But maybe that's dated?
> In theory, I have a referenced project that gives me preprocessor 
> variables that I should be able to pass to HeatDirectory but nothing 
> I've tried has seemed to work.
>
> Below is a one of the many things I've tried and high-level what I 
> think needs to happen but I'm clearly missing some concept or 
> syntactical sugar to make it actually work. I've tried every variation 
> on this theme that I can think of but each time either the project 
> won't load, it complains that Heat wasn't passed a Directory value, or 
> the directory points at the installation project's output folder instead of the reference project.
>
> Would love any feedback/guidance on how to point Heat at a referenced 
> project and consume the entirety of its output.
>
>
>
> <PropertyGroup>
>
> <DefineConstants>GatewayFolder=%(var.ProductAgentGateway.TargetDir)</D
> efineConstants>
> </PropertyGroup>
>
> ...
>
> <ItemGroup>
>                 <ProjectReference
> Include="..\Product.AgentGateway\Product.AgentGateway.csproj">
>                   <Name>ProductAgentGateway</Name>
>                   <Project>{70d701d1-1909-4cca-936e-0dd641ad0dba}</Project>
>                   <Private>True</Private>
>                   <DoNotHarvest>True</DoNotHarvest>
>
> <RefProjectOutputGroups>Binaries;Content;Satellites</RefProjectOutputGroups>
>                   <RefTargetDir>INSTALLFOLDER</RefTargetDir>
>                 </ProjectReference>
> </ItemGroup>
>
>  ...
>
> <Target Name="BeforeBuild">
> <HeatDirectory
>                 AutogenerateGuids="true"
>                 ComponentGroupName="ProductAgentGateway"
>                 Directory="$(GatewayFolder)"
>                 DirectoryRefId="INSTALLFOLDER"
>                 NoLogo="true"
>                 OutputFile="$(ProjectDir)\Files.wxs"
>                 PreprocessorVariable="var.GatewayFolder"
>                 SuppressCom="true"
>                 SuppressRegistry="true"
>                 SuppressRootDirectory="true"
>                 ToolPath="$(WixToolPath)"
>                 Transforms="Filter.xsl"
> />
>
> ____________________________________________________________________
> WiX Toolset Users Mailing List provided by FireGiant
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Furld
> efense.proofpoint.com%2Fv2%2Furl%3Fu%3Dhttp-3A__www.firegiant.com_&amp
> ;data=04%7C01%7Cbryand%40recastsoftware.com%7C9b6ce5011e914523975a08d9
> c0a534be%7C9315bb44634846c6bd378880b87e774e%7C0%7C0%7C6377526382498717
> 95%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI
> 6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=hFcT7973ID%2BQpJLjmDd6ZpgOG76
> Jd3wqEZyELkIXMHI%3D&reserved=0
> &d=DwICAg&c=9mghv0deYPYDGP-W745IEdQLV1kHpn4XJRvR6xMRXtA&r=Hblpuym5RtUs
> _4R6qwcviv7o1-X2VNe9YBkPtiuw4mw&m=wzc8yvqs-GaSbHQtVMZifumBjrvabG00EdhU
> MnMJ_kxjLhmnXuzapfBYyNntZkx6&s=tArU60MZ7G-tSSrTZxAHLGJrN8TJVlFw1geXmwF
> xqTA&e=
>

____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Furldefense.proofpoint.com%2Fv2%2Furl%3Fu%3Dhttp-3A__www.firegiant.com_%26d%3DDwICAg%26c%3D9mghv0deYPYDGP-W745IEdQLV1kHpn4XJRvR6xMRXtA%26r%3DHblpuym5RtUs_4R6qwcviv7o1-X2VNe9YBkPtiuw4mw%26m%3Dwzc8yvqs-GaSbHQtVMZifumBjrvabG00EdhUMnMJ_kxjLhmnXuzapfBYyNntZkx6%26s%3DtArU60MZ7G-tSSrTZxAHLGJrN8TJVlFw1geXmwFxqTA%26e%3D&data=04%7C01%7Cbryand%40recastsoftware.com%7C9b6ce5011e914523975a08d9c0a534be%7C9315bb44634846c6bd378880b87e774e%7C0%7C0%7C637752638249871795%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=pGCzoE77pZd9f0dxjJsAvpGZiWHdkK8ay5GZiPxaMu4%3D&reserved=0
Please be advised that this email may contain confidential information. If you are not the intended recipient, please notify us by email by replying to the sender and delete this message. The sender disclaims that the content of this email constitutes an offer to enter into, or the acceptance of, any agreement; provided that the foregoing does not invalidate the binding effect of any digital or other electronic reproduction of a manual signature that is included in any attachment.

____________________________________________________________________
WiX Toolset Users Mailing List provided by FireGiant https://nam11.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.firegiant.com%2F&data=04%7C01%7Cbryand%40recastsoftware.com%7C9b6ce5011e914523975a08d9c0a534be%7C9315bb44634846c6bd378880b87e774e%7C0%7C0%7C637752638249871795%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&sdata=Mj4Gg2hSRnjxZSvQSYTz95ecLgzS6Z30d5t%2BeIt%2BYnY%3D&reserved=0



More information about the wix-users mailing list