I've always used separate project files on windows and linux, in order to 
include different compiler symbols, in order to make projects build with 
different dependencies. I've been chastised here for doing it, so I'd like to 
find a better way. (Miguel and others tore apart a pull request, saying I 
should never check __MONO__, if I need behavior to be different on windows and 
non-windows, I need to use a runtime check. The problem is, as described below, 
the runtime check can't build or run on windows, so I'd like to figure out how 
it should be done).

Right now, I have a class, which is using Mono.Unix.Native, because of a method 
that does this: 
    if (Type.GetType("Mono.Runtime") != null) {
        Syscall.chmod(...);
    }

When built and run on mono, works great. The problem is building and running on 
windows. In order to make it build, I copied Mono.Posix.dll into the project 
and referenced it, with CopyLocal = False. This way, Mono.Posix.dll doesn't get 
copied to the build directory, which is good because it's already present on 
mono systems, and not needed on windows systems - the only reason for it to 
exist in the project is because windows can't build without it.

So it builds. But unfortunately, it won't run on windows. It throws 
FileNotFoundException "Mono.Posix.dll" before evaluating the if-clause.

The workaround I've found is to create a wrapper class MonoSpecific, so the 
if-clause and the Mono.Posix call are not in the same file. But this is clearly 
a hack. Is there a better way?

Hello.cs:
    using System;
    namespace helloProject
    {
        static class Hello
        {
            static void ChangePermsIfNecessary()
            {
                if (Type.GetType("Mono.Runtime") != null) {
                    MonoSpecific.DoChmod();
                }
            }
        }
    }

MonoSpecific.cs:
    using System;
    using Mono.Unix.Native;
    namespace helloProject
    {
        static class MonoSpecific
        {
            static void DoChmod()
            {
                Syscall.chmod(...);
            }
        }
    }

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to