dotnet / dotnet/msbuild

MSBuild is loading the wrong task architecture

Open
#7,382 5 comments 0 reactions 0 assignees View on GitHub
bug has-repro triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

### Issue Description
64-bit MSBuild loads 32-bit task in-proc. Part of the issue here: https://github.com/wixtoolset/issues/issues/6720.

### Steps to Reproduce
1. Clone https://github.com/rseanhall/wix4.
2. Checkout the msbuild-task-arch-issue branch.
3. Run src\setupenv.cmd (might need to download the latest nuget.exe into C:\Programs).
4. Run build.cmd.

Binlogs are created in build\logs.

### Expected Behavior
All tests pass in the src\wix\test\WixToolsetTest.Sdk project.

### Actual Behavior
`WixToolsetTest.Sdk.MsbuildFixture.CanBuildSimpleMsiPackageWithMergeModule` test fails in the 64-bit configuration.

```
C:\src\mywix4\build\wix\Debug\publish\WixToolset.Sdk\tools\wix.targets(590,5): BadImageFormatException: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
at WixToolset.Core.Native.Msm.MsmInterop.MergeModGetClassObject(Guid clsid, Guid iid)
at WixToolset.Core.Native.Msm.MsmInterop.GetMsmMerge() in C:\src\mywix4\src\wix\WixToolset.Core.Native\Msm\MsmInterop.cs:line 45
at WixToolset.Core.WindowsInstaller.Bind.ExtractMergeModuleFilesCommand.Execute() in C:\src\mywix4\src\wix\WixToolset.Core.WindowsInstaller\Bind\ExtractMergeModuleFilesCommand.cs:line 56
at WixToolset.Core.WindowsInstaller.Bind.BindDatabaseCommand.Execute() in C:\src\mywix4\src\wix\WixToolset.Core.WindowsInstaller\Bind\BindDatabaseCommand.cs:line 244
at WixToolset.Core.WindowsInstaller.MsiBackend.Bind(IBindContext context) in C:\src\mywix4\src\wix\WixToolset.Core.WindowsInstaller\MsiBackend.cs:line 31
at WixToolset.Core.Binder.BackendBind(IBindContext context) in C:\src\mywix4\src\wix\WixToolset.Core\Binder.cs:line 67
at WixToolset.Core.Binder.Bind(IBindContext context) in C:\src\mywix4\src\wix\WixToolset.Core\Binder.cs:line 40
at WixToolset.Core.CommandLine.BuildCommand.BindPhase(Intermediate output, IReadOnlyCollection`1 localizations, IReadOnlyCollection`1 filterCultures, String cabCachePath, IReadOnlyCollection`1 bindPaths, CancellationToken cancellationToken) in C:\src\mywix4\src\wix\WixToolset.Core\CommandLine\BuildCommand.cs:line 360
at WixToolset.Core.CommandLine.BuildCommand.ExecuteAsync(CancellationToken cancellationToken) in C:\src\mywix4\src\wix\WixToolset.Core\CommandLine\BuildCommand.cs:line 169
at WixToolset.BuildTasks.WixExeBaseTask.ExecuteCoreAsync(IWixToolsetCoreServiceProvider coreProvider, String commandLineString, CancellationToken cancellationToken) in C:\src\mywix4\src\wix\WixToolset.BuildTasks\WixExeBaseTask_Inproc.cs:line 24
at WixToolset.BuildTasks.ToolsetTask.ExecuteInProc(String commandLineString) in C:\src\mywix4\src\wix\WixToolset.BuildTasks\ToolsetTask_InProc.cs:line 42
[C:\Users\rhall\AppData\Local\Temp\5icgguio.okw\MergeMsiPackage\MergeMsiPackage.wixproj]
```

`mergemod.dll` is a native DLL that needs to match the process's architecture and is the one that is causing this failure.

### Analysis
The test is launching MSBuild from `C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\amd64\MSBuild.exe`. We have our tasks defined at https://github.com/rseanhall/wix4/blob/6a3a21a9990020e56acbf930f52b479b5d4d08d4/src/wix/WixToolset.Sdk/tools/wix.targets#L142:

```



```

`WixTasksPath64` is always defined in .NET Framework MSBuild, so the task should be loaded from the `WixTasksPath64` path.

The very unusual thing about this issue is that it works fine if initializing the command prompt from `C:\Program Files\Microsoft Visual Studio\2022\Enterprise\Common7\Tools\vsdevcmd.bat`.

We have a build process issue that is causing 64-bit dlls to be in the 32-bit folder (`build\wix\Debug\publish\WixToolset.Sdk\tools\net472\x86`). That test should always be failing in the 32-bit configuration, and always passing in the 64-bit configuration. Instead, both configurations are passing when initialized through `vsdevcmd.bat` and both configuration are failing otherwise.

### Versions & Configurations
`msbuild -version` output:
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

17.0.0.52104

### Attach a binlog
[MergeMsiPackage.MSBuild64.zip](https://github.com/dotnet/msbuild/files/8036729/MergeMsiPackage.MSBuild64.zip)
[MergeMsiPackage.rest.zip](https://github.com/dotnet/msbuild/files/8036903/MergeMsiPackage.rest.zip)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.