1

在我的 C# 项目中,我有导入,但在 Mono(即使在编译时!)中也不能很好地工作。我想排除 Mono 中的一些代码(在编译时)。我以前用过类似的东西:

#if !__MonoCS__
...
#endif

但是,此常量未在 Mono 4.0.2、OSX 中定义。可能只在 DNVM 或 Roslyn 上。

如果我在文件开头手动定义__MonoCS__常量。一切正常。

这个平台上是否有任何__MonoCS__等价物?


如果这件事,我的项目是基于 asp.net vnext 的 webapi。我使用以下命令运行该项目:

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

对于许多特定信息,“为什么我在编译时需要它?”的答案。该项目仅在以下代码被注释掉时才有效。

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)
    );
}
4

1 回答 1

1

将该代码移至不同的函数。

只要您不在没有该 DLL 的平台上调用该函数,一切都会好起来的。

于 2015-07-05T23:12:08.727 回答