简体   繁体   中英

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; how do you get the versions of C# and of the .NET or Mono framework currently being used?

EDIT: I am NOT asking how to find whether you are using Mono or .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 ).

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

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)?

and for detecting the .NET framework's version currently used at runtime for execution you can check Environment.Version

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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