AaronRobinsonMSFT / DNNE

Prototype native exports for a .NET Assembly.
MIT License
406 stars 41 forks source link

Visual Studio Amd64 on ARM64 causes issue on .NET SDK #130

Closed AaronRobinsonMSFT closed 12 months ago

AaronRobinsonMSFT commented 2 years ago

Visual Studio installations install a COM for version/location discovery that matches its architecture. This presents an issue if the .NET SDK is different from the Visual Studio it is using to query for compiler locations.

Example of failure

...\.nuget\packages\dnne\1.0.27\build\DNNE.targets(121,5): error MSB4018: The "CreateCompileCommand" task failed unexpectedly. [...\src\libraries\
System.Runtime.InteropServices\tests\TestAssets\NativeExports\NativeExports.csproj]
...\.nuget\packages\dnne\1.0.27\build\DNNE.targets(121,5): error MSB4018: System.BadImageFormatException: Retrieving the COM class factory for component with CL
SID {177F0C4A-1CD3-4DE7-A32C-71DBBB9FA36D} failed due to the following error: 800700c1  is not a valid Win32 application. (0x800700C1). [...\src\libraries\Sy
stem.Runtime.InteropServices\tests\TestAssets\NativeExports\NativeExports.csproj]
...\.nuget\packages\dnne\1.0.27\build\DNNE.targets(121,5): error MSB4018:    at System.RuntimeTypeHandle.AllocateComObject(Void* pClassFactory) [C:\repos\runtim
e0\src\libraries\System.Runtime.InteropServices\tests\TestAssets\NativeExports\NativeExports.csproj]
...\.nuget\packages\dnne\1.0.27\build\DNNE.targets(121,5): error MSB4018:    at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean wrapExc
eptions) [...\src\libraries\System.Runtime.InteropServices\tests\TestAssets\NativeExports\NativeExports.csproj]
...\.nuget\packages\dnne\1.0.27\build\DNNE.targets(121,5): error MSB4018:    at DNNE.BuildTasks.Windows.GetLatestVSWithVCInstallPath() in D:\a\DNNE\DNNE\src\msb
uild\DNNE.BuildTasks\Windows.cs:line 198 [...\src\libraries\System.Runtime.InteropServices\tests\TestAssets\NativeExports\NativeExports.csproj]

A more flexible solution would be to use vswhere instead of the COM server. The below is an example from the dotnet/arcade.

https://github.com/dotnet/arcade/blob/456cea4762a3c49420e699828ced3066ebeb68a0/src/Microsoft.DotNet.CMake.Sdk/build/Microsoft.DotNet.CMake.Sdk.targets#L98-L104