Search code examples
c#monoroslyndnvm

__MonoCS__ constant equivalent in Mono, Roslyn, Dnvm


I have imports, that does not work well in Mono (even on compile time!), in my C# project. I want to exclude some code in Mono (in compile time). I've used something similar before:

#if !__MonoCS__
...
#endif

However this constant is not defined in Mono 4.0.2, OSX. Probably only on DNVM or Roslyn.

If I define the __MonoCS__ constant manually in the beginning of the file. Everything works fine.

Is there any __MonoCS__ equivalent on this platform?


If this matter, my project is asp.net vnext based webapi. And I run the project with the following command:

/Users/buraktamturk/.dnx/runtimes/dnx-mono.1.0.0-beta4/bin/dnx . kestrel

For many specific information, the answer of "why i need it in compile time?". The project only working when the following code is commented out.

if(false) { // yes, false!
  var certificate = new X509Certificate2(config.Get("google:pkeyloc"), config.Get("google:pkeypw"), X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable);

   credential = new ServiceAccountCredential(
              new ServiceAccountCredential.Initializer(config.Get("google:serviceacc"))
              {
                  Scopes = new[] { StorageService.Scope.DevstorageFullControl }
              }.FromCertificate(certificate)
    );
}

Solution

  • Move that code to a different function.

    As long as you don't call that function on platforms that don't have that DLL, everything will be fine.