Пример #1
0
        public override void Invoke()
        {
            if (NetFx && NetCore)
            {
                throw new DiagnosticsException("Cannot specify both -netfx and -netcore options");
            }
            if (NetFx || NetCore)
            {
                string name = NetFx ? "desktop .NET Framework" : ".NET Core";
                foreach (IRuntime runtime in RuntimeService.EnumerateRuntimes())
                {
                    if (NetFx && runtime.RuntimeType == RuntimeType.Desktop ||
                        NetCore && runtime.RuntimeType == RuntimeType.NetCore)
                    {
                        ContextService.SetCurrentRuntime(runtime.Id);
                        WriteLine("Switched to {0} runtime successfully", name);
                        return;
                    }
                }
                WriteLineError("The {0} runtime is not loaded", name);
            }
            else
            {
                // Display the current runtime star ("*") only if there is more than one runtime
                bool displayStar = RuntimeService.EnumerateRuntimes().Count() > 1;

                foreach (IRuntime runtime in RuntimeService.EnumerateRuntimes())
                {
                    string current = displayStar ? (runtime == ContextService.GetCurrentRuntime() ? "*" : " ") : "";
                    Write(current);
                    Write(runtime.ToString());
                }
            }
        }
Пример #2
0
        public override void Invoke()
        {
            if (NetFx && NetCore)
            {
                throw new DiagnosticsException("Cannot specify both -netfx and -netcore options");
            }
            if (NetFx || NetCore)
            {
                string name = NetFx ? "desktop .NET Framework" : ".NET Core";
                foreach (IRuntime runtime in RuntimeService.EnumerateRuntimes())
                {
                    if (NetFx && runtime.RuntimeType == RuntimeType.Desktop ||
                        NetCore && runtime.RuntimeType == RuntimeType.NetCore)
                    {
                        ContextService.SetCurrentRuntime(runtime.Id);
                        WriteLine("Switched to {0} runtime successfully", name);
                        return;
                    }
                }
                WriteLineError("The {0} runtime is not loaded", name);
            }
            else
            {
                // Display the current runtime star ("*") only if there is more than one runtime
                bool displayStar = RuntimeService.EnumerateRuntimes().Count() > 1;

                foreach (IRuntime runtime in RuntimeService.EnumerateRuntimes())
                {
                    string current = displayStar ? (runtime == ContextService.GetCurrentRuntime() ? "*" : " ") : "";
                    Write(current);
                    Write(runtime.ToString());
                    ClrInfo clrInfo = runtime.Services.GetService <ClrInfo>();
                    if (clrInfo is not null)
                    {
                        unsafe
                        {
                            if (clrInfo.SingleFileRuntimeInfo.HasValue)
                            {
                                RuntimeInfo runtimeInfo = clrInfo.SingleFileRuntimeInfo.Value;
                                WriteLine("    Signature:   {0}", Encoding.ASCII.GetString(runtimeInfo.Signature, RuntimeInfo.SignatureValueLength - 1));
                                WriteLine("    Version:     {0}", runtimeInfo.Version);
                                if (Target.OperatingSystem == OSPlatform.Windows)
                                {
                                    WriteLine("    Runtime:     {0}", GetWindowsIndex(runtimeInfo.RuntimeModuleIndex));
                                    WriteLine("    DBI:         {0}", GetWindowsIndex(runtimeInfo.DbiModuleIndex));
                                    WriteLine("    DAC:         {0}", GetWindowsIndex(runtimeInfo.DacModuleIndex));
                                }
                                else
                                {
                                    WriteLine("    Runtime:     {0}", GetUnixIndex(runtimeInfo.RuntimeModuleIndex));
                                    WriteLine("    DBI:         {0}", GetUnixIndex(runtimeInfo.DbiModuleIndex));
                                    WriteLine("    DAC:         {0}", GetUnixIndex(runtimeInfo.DacModuleIndex));
                                }
                            }
                        }
                    }
                }
            }
        }