简体   繁体   中英

At runtime how does one determine which mono version is being used?

On a system multiple mono runtime versions may exist. For example

/usr/bin/mono
/usr/local/bin/mono

When creating a new managed process from a C# application it can be useful to be explicit about which mono version you want to run it with. (The mono in the path may not be the mono being used to run the current process)

Using the Process class to get the current process name returns the assembly that mono is running not mono itself.

What is the best way to determine which mono runtime is currently being used?

On Linux, the process Id and /proc can be used to find the mono executable.

string monopath = String.Format("/proc/{0}/exe", Process.GetCurrentProcess().Id);

monopath will be a symlink to the current executing mono runtime, and can be used to launch a new process:

Process.Start(monopath);

You can use

    Type monoRuntimeType;
    MethodInfo getDisplayNameMethod;
    if ((monoRuntimeType = typeof(object).Assembly.GetType("Mono.Runtime")) != null &&
        (getDisplayNameMethod = monoRuntimeType.GetMethod("GetDisplayName",
          BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.ExactBinding, null,
                  Type.EmptyTypes, null)) != null)

    Console.WriteLine("Mono " + (string)getDisplayNameMethod.Invoke(null, null));

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