1

Does anyone know how to specify a DLL specific to OS in Mono/.Net?

I have two DLLs, a linux_taxes.dll and windows_taxes.dll that reference managed code. (In reality they both have the same name) If I use the windows_taxes.dll it compiles fine in windows and if I use the linux_taxes.dll it compiles fine in linux. Since they have the same name (in reality) I only have one reference to taxes.dll and just manually overwrite the dlls depending which OS I am on. This is a pain, and I was wondering if there was a way to automate this DLL overwriting or even better point to a specific DLL when on Linux and point to another DLL when I am on Windows. I looked into Config DLL maps with code similar to this:

<dllmap os="linux" dll="taxes.dll" target="linux_taxes.dll"></dllmap>
<dllmap os="windows" dll="taxes.dll" target="windows_taxes.dll"></dllmap>

But this did not work and I think I might be heading in the wrong direction...

I was also thinking maybe I could make a custom target to copy over the correct DLLs from some subfolder to the bin but I am unsure of how to make targets specific for mono that would do this.

Any help would be appreciated. Thanks!

1 Answers1

0

You use the dllmap directive in app.config to map unmanaged shared library referenced by P/Invoke in your assembly to a different unmanaged shared library. It seems that dllmap is no use for you because if I understand your problem correctly you have two managed libraries a.k.a. assemblies:

  1. taxes.dll that works on Windows
  2. taxes.dll that works on Linux

You say these two assemblies are interchangeable on file system level so I guess they implement exactly the same interfaces, classes etc. The most beautiful thing about .NET/Mono assemblies is they can be easily used on different platforms without the need for rebuilding. Your code can detect execution platform in runtime and use appropriate code for that platform i.e.:

if ((System.Environment.OSVersion.Platform == System.PlatformID.Unix) ||
    (System.Environment.OSVersion.Platform == System.PlatformID.MacOSX))
{
    // Code for Unix platform
}
else
{
    // Code for Windows platform
}

I believe that merging your two assemblies into the single multiplatform assembly would be the most convenient solution and would solve your problem once and for all but it would of course require you to change the implementation of those two assemblies.

Other than that you can always create new solution configuration named "Linux" (or even "LinuxDebug" for debug build and "LinuxRelease" for release build) manually edit csproj files and add condition to your assembly reference. See this answer and referenced article for a detailed explanation on how to do that.

Community
  • 1
  • 1
jariq
  • 11,681
  • 3
  • 33
  • 52
  • Yep that worked. Thanks! They were using the same namespace so I had give one an Alias so I could differentiate between them in the code. Then I just created a class to select which code to use for which OS. That's also a good idea about combining them into a single multiplatform assembly, Ill probably do that when I get more time. Thanks Again! – user3551149 Apr 21 '14 at 02:12