[Mono-list] Built-in Conditional Directives for various platforms #IF MONO, #IF WINDOWS_DOTNET, #IF MACOSX ?

Jonathan Pryor jonpryor at vt.edu
Sun Apr 4 16:25:46 EDT 2010

On Sat, 2010-04-03 at 18:36 +0200, cimodev wrote:
> are there built-in conditional directives in MONO like

In general, compile-time conditionals are to be avoided, as it means you
have to recompile your code for each target platform.  Runtime checks
are consequently preferred.

That said...

> On Windows, i have to write "using System.Data.SQlite", and on
> MONO-based Systems i write "using Mono.Data.Sqlite".
> So, its not enough to check the platform within running code, but while
> compile-time for using-declaratives.

The appropriate answer is: Don't Do That.

There are two possible approaches:

1. Build against ONLY Mono.Data.Sqlite.dll, and bundle
Mono.Data.Sqlite.dll and the Windows SQLITE3.DLL with your app.

On Unix, this will use the system-installed libsqlite3.so.0 shared
library with the Mono.Data.Sqlite ADO.NET provider bundled with your app
(or use the one in the GAC if the version number matches).

On Windows, this will use the Mono.Data.Sqlite.dll bundled with your app
and the SQLITE3.DLL bundled with your app.

2. Build against ONLY System.Data.SQLite.dll.

This is slightly trickier, as the "default" assembly is a mixed-mode
assembly that won't run under Mono.  However, they DO provide a
managed-only assembly for use with Mono:


(It's the "SQLite-" link at the normal
download page.)

Thus, when creating an installer for Windows, you can bundle the
single-file mixed-mode System.Data.SQLite.dll assembly, or bundle the
managed-only System.Data.SQLite.dll and the native SQLITE3.DLL library.

When creating an installer for Linux, bundle the managed-only
System.Data.SQLite.dll assembly and a System.Data.SQLite.dll.config file
which remaps sqlite3 to e.g. libsqlite3.so.0 (assuming you want to use
the system-installed libsqlite3.so.0 shared library):

          <dllmap dll="sqlite3" target="libsqlite3.so.0" os="!windows"/>

(Though this might not be necessary, as /etc/mono/config may also
contain this remapping.  Try it and see.)

I'm reasonably sure that standardizing on one of the SQLite ADO.NET
providers will save you more pain than trying to deal with multiple
platform-specific builds. :-)

 - Jon

More information about the Mono-list mailing list