如何有条件地为 Mono 和 Microsoft .NET 编译我的 C#? [英] How can I conditionally compile my C# for Mono vs. Microsoft .NET?

查看:17
本文介绍了如何有条件地为 Mono 和 Microsoft .NET 编译我的 C#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一个条件编译开关,它知道我是为单声道还是 MS .NET 运行时进行编译.我怎样才能做到这一点?

I need a conditional compilation switch that knows if I am compiling for the mono or MS .NET runtime. How can I do this?

推荐答案

Mono编译器定义了__MonoCS__

但是,但是,但是,Mono 的全部意义在于,您可以使用 VS 构建的程序集并在 Mono 上运行它,反之亦然.

BUT, BUT, BUT, the whole point of Mono is that you can take an assembly that you built with VS and run it on Mono, or vice versa.

在我看来,如果您需要区分 Mono 和 MS.NET,那么您需要在运行时做出这些决定.

It seems to me that if you need to have Mono vs MS.NET differences, then you need to be making those decisions at run-time.

在运行时检测 Mono 的标准方法是:

The standard way to detect Mono at Runtime is:

bool runningOnMono = Type.GetType ("Mono.Runtime") != null;

这篇关于如何有条件地为 Mono 和 Microsoft .NET 编译我的 C#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆