11

I have an issue with heat.exe as soon as I build my project in MSBuild. I get this error message:

Unhandled Exception: System.BadImageFormatException: Could not load file or assembly 'file:///C:\Program Files (x86)\WiX Toolset v3.11\bin\Heat.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format.

I have looked up a possible solution on stackoverflow here: Referred links

I've tryed to change my configuration in all sorts of ways but can't get a hold of what is missing.

This is how I have configured right now. I want to be able to target both x64 and x86 platform.

<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x64' ">
<OutputPath>..\..\BuildArtifacts\SetupProjects\Myproject</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Debug</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x64' ">
<OutputPath>..\..\BuildArtifacts\SetupProjects\Myproject</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Release</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<OutputPath>..\..\BuildArtifacts\SetupProjects\Myproject</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Debug</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>..\..\BuildArtifacts\SetupProjects\Myproject</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>Release</DefineConstants>
</PropertyGroup>

Any help appreciated,

Sebastian
  • 219
  • 2
  • 13
  • The first thing that comes to mind: I believe `heat.exe` has problems with **64-bit COM files**. Do you have any of those in your project? Just mentioning it, there is probably another cause (as well). Maybe try to test by removing the COM files and run a build - if possible. – Stein Åsmul Apr 23 '18 at 17:04

4 Answers4

31

Since msbuild runs as a 64bit exe, it will fail to load the 32bit heat.exe. To fix this issue, processes have to run seperately. This can be done by adding this to a PropertyGroup:

<RunWixToolsOutOfProc Condition=" '$(PROCESSOR_ARCHITECTURE)'!='x86' ">true</RunWixToolsOutOfProc>

But thats not enough. Heat does successfully ignore that Property. Instead you have to use the Property RunAsSeparateProcess:

<HeatDirectory
        ....
    RunAsSeparateProcess="$(RunWixToolsOutOfProc)" />

See: https://github.com/wixtoolset/issues/issues/2467#issuecomment-736519622

kuch3n
  • 441
  • 4
  • 10
3

UPDATE: There seems to be a closed issue in WiX's issues database which you should check out first of all. Please check if the problem description is reminiscent of what you experience: https://github.com/wixtoolset/issues/issues/2467

It seems to relate to 64-bit MSBuild - and the exception is the same as you describe. Maybe read comments from the bottom up - there is a recent comment at the bottom from 2017.

My naive first thought is whether you can run the 32-bit MSBuild instead? (I don't know much about this). Or as mentioned in the bottom comment in the linked issue, run the executable as an external process?


Old Answer: The first thing that comes to mind: I believe heat.exe has problems with 64-bit COM files. Do you have any of those in your project? Just mentioning it, there is probably another cause (as well). Maybe try to test by removing the COM files and run a build - if possible.

I believe this issue is also still there. I don't know much about it, but I've been informed that FireGiant's commercial kit (in other words not free) handles advanced harvesting with 64-bit files.

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • Yes, this was the bottom line of the issue. I recently solved it by forcing my cake script to use MSBuildPlatform x86. Thanks for the input :). – Sebastian Apr 25 '18 at 07:47
  • Great that it works for you now, and thanks for informing us about the issue. The 64-bit COM-file issue will probably be solved soon as well. – Stein Åsmul Apr 25 '18 at 16:08
1

Since i switched to Visual Studio 2022 my command MSBuild c:\project\Setup\Setup.wixproj doesn't work anymore. I solved this by directly calling the 32Bit MSBuild executable:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe c:\project\Setup\Setup.wixproj
Marco G
  • 102
  • 5
  • Huh? Where do you put this code? Having the same problem when building Installer via usual means (building the installer project). Not clear from your answer where this code goes. – stigzler May 07 '22 at 10:44
  • I build it in the command prompt (CMD). I needed it to check for the build server where I have to use MSBUILD and not VS. – Marco G May 08 '22 at 13:15
0

I managed to fix this issue by changing wixproj from

<Target Name="BeforeBuild">
  <HeatDirectory Directory="$(MSBuildThisFileDirectory)lib\" PreprocessorVariable="var.HarvestPath" OutputFile=".\clients\sftp\OmsFileServer\SFTPFileServerInstaller\SFTPFileServerInstaller\HeatGeneratedFileList.wxs" ComponentGroupName="HeatGenerated" DirectoryRefId="INSTALLFOLDER" AutogenerateGuids="true" ToolPath="$(WixToolPath)" SuppressUniqueIds="true" SuppressFragments="true" SuppressRegistry="true" SuppressRootDirectory="true"/>
</Target>

to

<PropertyGroup>
  <InstallerPlatform>x64</InstallerPlatform>
  <Platform>x64</Platform>
</PropertyGroup>
<Target Name="BeforeBuild">
  <Exec Command='"$(WIX)bin\heat.exe" dir "$(MSBuildThisFileDirectory)lib" -cg HeatGenerated -dr INSTALLFOLDER -sreg -srd -var var.HarvestPath -ag -sfrag -suid -out "$(MSBuildThisFileDirectory)HeatGeneratedFileList.wxs"'/>
</Target>

I realized because my cake script asks MSBuild-x64 to build the solution, it somehow can't run a 32bit HeatDirectory command, but I'm not sure how exactly Exec works in an x64 pipeline and HeatDirectory doesn't.

Moreover, a 64 bit application definitely can execute a 32 bit app and it's not possible only the other way. But nothing else on the internet worked for me.

Bizhan
  • 16,157
  • 9
  • 63
  • 101