0

I'm writing a custom-action C# DLL that will be used from my WiX MSI installer. That DLL makes several pinvoke calls to another (unmanaged) DLL, which I need to include with my managed DLL (according to this post). I can do so by adding the unmanaged DLL to my C# project as a link from its compilation folder (from its C++ project in Visual Studio.)

The question is how do I add it depending on the bitness of the C# project and its type: x86 vs x64 and debug vs release?

For instance, when I build my custom-action C# DLL as x64, I need to include the 64-bit build of the unmanaged DLL. But when I build it as x86, I need a different version of the unmanaged DLL.

c00000fd
  • 20,994
  • 29
  • 177
  • 400
  • There is an "Exclude from build" option that is config-/platform-dependent. So, include all the files in all configs/platforms, then set that property for each file accordingly. Or have I missed the point? (Right-click on file in Solution Explorer, then "Properties -> General".) – Adrian Mole Feb 28 '22 at 15:28
  • @AdrianMole this works for a C++ project, but I don't see Properties -> General in a managed C# project. Am I missing something? – c00000fd Feb 28 '22 at 15:33
  • Hmm. Probably me jumping to conclusions. Curiouser and curiouser ... – Adrian Mole Feb 28 '22 at 15:35
  • One way I have seen x86/x64 handled is to include both x86 and x64 dlls, and load the correct one at runtime, that way your installer does not have to do anything special. See [SetDllImportResolver](https://learn.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.nativelibrary.setdllimportresolver?view=netcore-3.0) and [github example](https://github.com/team-charls/charls-native-dotnet/blob/main/src/Interop.cs) – JonasH Feb 28 '22 at 16:05
  • @JonasH: wow, there's no other option. I checked your link and it says that it applies to .NET Core. My project is using .NET 4.7.2 – c00000fd Feb 28 '22 at 16:13
  • Ok, I found the answer: https://stackoverflow.com/a/71386885/843732 – c00000fd Mar 07 '22 at 20:38

0 Answers0