Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setup using HeatDirectory task kills Visual Studio 2022 #6636

Closed
henning-krause opened this issue Nov 14, 2021 · 8 comments · May be fixed by wixtoolset/wix3#547
Closed

Setup using HeatDirectory task kills Visual Studio 2022 #6636

henning-krause opened this issue Nov 14, 2021 · 8 comments · May be fixed by wixtoolset/wix3#547
Assignees
Labels

Comments

@henning-krause
Copy link

  • 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
Copy link

Yes. VS2022 is crashing with preview extension.

@barnson barnson self-assigned this Dec 2, 2021
@barnson
Copy link
Member

barnson commented Dec 2, 2021

You're calling the HeatDirectory target directly, so you're responsible for running it out of proc when necessary. wix.targets passes

RunAsSeparateProcess="$(RunWixToolsOutOfProc)"

RunWixToolsOutOfProc is set to true when not running in a 32-bit process.

@barnson barnson closed this as completed Dec 2, 2021
@barnson barnson added notabug and removed triage labels Dec 2, 2021
@StevenBonePgh
Copy link

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 the Architecture="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
Copy link
Member

barnson commented Dec 2, 2021

The task is MSIL; Heat.exe is x86 to support registry harvesting.

@Mertsch
Copy link

Mertsch commented 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
Copy link

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
Copy link
Member

barnson commented Dec 5, 2021

Harvesting self-registration requires an architecture-specific process because it loads architecture-specific DLLs.

@PawOrmstrupMadsen

This comment was marked as abuse.

@wixtoolset wixtoolset locked as resolved and limited conversation to collaborators Sep 6, 2022
davkean added a commit to davkean/wix3 that referenced this issue Oct 14, 2022
Fixes: wixtoolset/issues#6636

MSBuild typically handles exceptions thrown directly by tasks and reports them as errors. WixToolTask.ExecuteTool, however, is forking its execution onto another thread and this thread is throwing when invoking Heat directly in-proc. This is crashing its host. This is wixtoolset#15 of all crashes in Visual Studio 17.3.

Handle the error and give a helpful message instead of crashing.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants