简体   繁体   English

如何查找正在使用的C#和.NET / Mono版本?

[英]How to find what versions of C# and .NET/Mono are being used?

You can use System.Environment.Version to the get the version of the CLR; 您可以使用System.Environment.Version来获取CLR的版本。 how do you get the versions of C# and of the .NET or Mono framework currently being used? 如何获取当前正在使用的C#版本和.NET或Mono框架?

EDIT: I am NOT asking how to find whether you are using Mono or .NET. 编辑:我不是问如何找到您正在使用Mono或.NET。 (The very first version of my question did ask that as a secondary question, but I deleted that almost immediately when I saw that question answered elsewhere.) The questions here are (1) how to figure out what version of C# you are working with, and (2) what version of .NET you have (as opposed to the version of the CLR, which isn't the same thing ). (我的问题的第一个版本确实将其作为第二个问题,但当我看到该问题在其他地方回答时,我几乎立即删除了该问题。)这里的问题是(1)如何确定您正在使用的C#版本,以及(2)您拥有的.NET版本(与CLR版本不同 )。

Checking if you're running in mono: 检查您是否在单声道中运行:

public static bool IsRunningOnMono ()
{
    return Type.GetType ("Mono.Runtime") != null;
}

Checking the mono version: 检查单声道版本:

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

If you're not in Mono, then you still use System.Environment.Version 如果您不在Mono中,那么您仍将使用System.Environment.Version

a very similar question has been asked already: 已经提出了一个非常类似的问题:

public static bool IsRunningOnMono ()
{
    return Type.GetType ("Mono.Runtime") != null;
}

How to detect which .NET runtime is being used (MS vs. Mono)? 如何检测正在使用哪个.NET运行时(MS与Mono)?

and for detecting the .NET framework's version currently used at runtime for execution you can check Environment.Version 并且要检测当前在运行时用于执行的.NET框架的版本,可以检查Environment.Version

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

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