简体   繁体   English

以编程方式确定Mono运行时版本

[英]Programmatically determining Mono runtime version

What is the recommended way to determine the Mono runtime version programmatically? 以编程方式确定Mono运行时版本的推荐方法是什么?

We have encountered various problems when our .Net application is used with older versions of Mono. 当我们的.Net应用程序与旧版本的Mono一起使用时,我们遇到了各种问题。 Sometimes we can work around these problems, if we know which version we are dealing with, but sometimes we can't. 有时我们可以解决这些问题,如果我们知道我们正在处理哪个版本,但有时我们不能。

The solution for us would be to detect the Mono version programmatically, and then we can transparently apply the workarounds. 我们的解决方案是以编程方式检测Mono版本,然后我们可以透明地应用变通方法。 If the Mono version is too old, then we would prompt the user to upgrade. 如果Mono版本太旧,那么我们会提示用户升级。

We can discover that Mono is our runtime with something like this: 我们可以发现Mono是我们的运行时,有这样的东西:

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

How can we also determine reliably the mono version without inferring it indirectly? 我们怎样才能可靠地确定单声道版本而不间接推断它? To be clear, we need the Mono release number, not the .Net CLR version number. 需要说明的是,我们需要Mono版本号,而不是.Net CLR版本号。

You can check the mono runtime version as: 您可以将单声道运行时版本检查为:

Type type = Type.GetType("Mono.Runtime");
if (type != null)
{
    MethodInfo displayName = type.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
    if (displayName != null)
        Console.WriteLine(displayName.Invoke(null, null));
}

Check this How to determine the revision from which current Mono runtime was built and installed? 选中此如何确定构建和安装当前Mono运行时的修订版本? for more details. 更多细节。

Here is another solution (without using reflection) 这是另一种解决方案(不使用反射)

[DllImport("__Internal", EntryPoint="mono_get_runtime_build_info")]
public extern static string GetMonoVersion();


Console.WriteLine("Mono version: {0}",GetMonoVersion());
Mono version: 3.12.0 (tarball Sat Feb  7 19:13:43 UTC 2015)

You can use this: 你可以用这个:

System.Reflection.Assembly.GetExecutingAssembly().ImageRuntimeVersion

It should give you the Mono CLR version, and as a bonus it will give you the CLR version on Windows. 它应该为您提供Mono CLR版本,作为奖励,它将为您提供Windows上的CLR版本。

http://msdn.microsoft.com/en-us/library/system.reflection.assembly.imageruntimeversion.aspx http://msdn.microsoft.com/en-us/library/system.reflection.assembly.imageruntimeversion.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM