/// <summary> /// Find the current runtime. /// </summary> public IRuntime GetCurrentRuntime() { if (_currentRuntime is null) { IEnumerable <IRuntime> runtimes = RuntimeService?.EnumerateRuntimes(); if (runtimes is not null) { // First check if there is a .NET Core runtime loaded foreach (IRuntime runtime in runtimes) { if (runtime.RuntimeType == RuntimeType.NetCore || runtime.RuntimeType == RuntimeType.SingleFile) { _currentRuntime = runtime; break; } } // If no .NET Core runtime, then check for desktop runtime if (_currentRuntime is null) { foreach (IRuntime runtime in runtimes) { if (runtime.RuntimeType == RuntimeType.Desktop) { _currentRuntime = runtime; break; } } } // If no core or desktop runtime, get the first one if any if (_currentRuntime is null) { _currentRuntime = runtimes.FirstOrDefault(); } } } return(_currentRuntime); }