- Sponsor
-
Notifications
You must be signed in to change notification settings - Fork 23
Closed
wixtoolset/wix3
#547Labels
Description
- Which version of WiX are you building with?
WiX Toolset v3.11
- Which version of Visual Studio are you building with (if any)?
Visual Studio 2022
- Which version of the WiX Toolset Visual Studio Extension are you building with (if any)?
1.0.0.12
- Which version of .NET are you building with?
.NET 4.8
- Describe the problem and the steps to reproduce it.
I'm trying to build my installer using MSBUild 17.0.0.52104 (Visual Studio 2022) from the Visual Studio. My setup includes this extra build target:
<Target Name="BeforeBuild">
<HeatDirectory AutogenerateGuids="true" SuppressRegistry="true" SuppressCom="true" SuppressRootDirectory="true" DirectoryRefId="ServiceRoot" SuppressFragments="true" PreprocessorVariable="var.DISTFOLDER" Transforms="TransformHeat.xslt" ComponentGroupName="ApplicationFiles" OutputFile="Files.wxs" Directory="$(DistFolder)" ToolPath="$(WixToolPath)" />
</Target>
This successfully runs with MSBuild from VS 2019 (x86), but crashes with MSBuild from VS2022 (x64) with this exception:
BeforeBuild:
C:\Program Files (x86)\WiX Toolset v3.11\bin\Heat.exe dir "..\..\build\src" -cg ApplicationFiles -dr ServiceRoot -scom -sreg -srd -var var.DISTFOLDER -ag -sfrag -t TransformHeat.xslt -out Files.wxs
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.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Microsoft.Tools.WindowsInstallerXml.Build.Tasks.WixToolTask.ExecuteToolThread(Object parameters)
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.
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadFrom(String assemblyFile, Evidence securityEvidence, Byte[] hashValue, AssemblyHashAlgorithm hashAlgorithm, Boolean forIntrospection, Boolean suppressSecurityChecks, StackCrawlMark& stackMark)
at System.Reflection.Assembly.LoadFrom(String assemblyFile)
at Microsoft.Tools.WindowsInstallerXml.Build.Tasks.WixToolTask.ExecuteToolThread(Object parameters)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart(Object obj)
Now, I fixed this by adding the attribute RunAsSeparateProcess="true"
to the HeatDirectory
task (as described in (#2570).
I just wanted to bring this issue to attention, because it kills Visual Studio 2022 reliably every time I build the setup if the RunAsSeparateProcess
is not set to true.
rajeshaz09, dcm99, TomJoosten, Sundow, geodeasic and 5 morepikobyte and amccool
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
rajeshaz09 commentedon Nov 27, 2021
Yes. VS2022 is crashing with preview extension.
barnson commentedon Dec 2, 2021
You're calling the
HeatDirectory
target directly, so you're responsible for running it out of proc when necessary. wix.targets passesRunAsSeparateProcess="$(RunWixToolsOutOfProc)"
RunWixToolsOutOfProc
is set totrue
when not running in a 32-bit process.StevenBonePgh commentedon Dec 2, 2021
Bob, I disagree that this should be closed. You are describing a workaround, which I had already provided. I don't think the workaround is/should be necessary. Please reference the following link: MSBuild and 64-bit Visual Studio 2022
I briefly took a look at the overall assembly used for this MsBuild task when I first discovered this issue and I can't understand why it cannot simply target AnyCpu. If I recall properly, Burn uses some native code that would limit this change, but I believe this is in a different assembly. I also believe that in Wix vNext this assembly is now AnyCpu.
If changing the build task to AnyCpu is not possible, declaring (in wix.targets)
UsingTask
with theArchitecture="x86"
attribute would let MsBuild do in/out of proc as necessary.Either of the above potential changes that can be made in Wix is an option that would not require a change to existing projects, as the workaround does. Leaving Wix as-is assumes that folks can figure out this change is necessary.
It is disturbing that this causes Visual Studio to crash. This fact makes it rather difficult to determine the underlying cause, as I can attest. Certainly MsBuild and Visual Studio could do a better job at error handling - and perhaps that would be able to point the finger at that specific build task, which may lead people here for the workaround.
barnson commentedon Dec 2, 2021
The task is MSIL; Heat.exe is x86 to support registry harvesting.
Mertsch commentedon Dec 3, 2021
I don't know if this is a good idea, since I never harvested registry entries, but:
Would it be useful to run in
Any CPU
and harvest the x64/x86 registry by default and have a switch that explicitly states to harvest the x86 registry (only effecting x64 system)zdavidsen commentedon Dec 3, 2021
If you want the tool to automatically run out of process, then you should probably be creating a HarvestDirectory item and just rely on the built-in targets to do the harvesting with the correct parameters
https://wixtoolset.org/documentation/manual/v3/msbuild/target_reference/harvestdirectory.html
barnson commentedon Dec 5, 2021
Harvesting self-registration requires an architecture-specific process because it loads architecture-specific DLLs.
11 remaining items