コード例 #1
0
        internal static ClrRuntime GetCurrentVersion()
        {
            if (!RuntimeInformation.IsWindows())
            {
                throw new NotSupportedException("Full .NET Framework supports Windows OS only.");
            }

            // this logic is put to a separate method to avoid any assembly loading issues on non Windows systems
            string sdkVersion = FrameworkVersionHelper.GetLatestNetDeveloperPackVersion();

            string version = sdkVersion
                             ?? FrameworkVersionHelper.GetFrameworkReleaseVersion(); // .NET Developer Pack is not installed

            switch (version)
            {
            case "4.6.1": return(Net461);

            case "4.6.2": return(Net462);

            case "4.7":   return(Net47);

            case "4.7.1": return(Net471);

            case "4.7.2": return(Net472);

            case "4.8":   return(Net48);

            default:     // unlikely to happen but theoretically possible
                return(new ClrRuntime(RuntimeMoniker.NotRecognized, $"net{version.Replace(".", null)}", $".NET {version}"));
            }
        }
コード例 #2
0
        private static IToolchain GetCurrentVersion()
        {
            if (!RuntimeInformation.IsWindows())
            {
                return(Net46); // we return .NET 4.6 which during validation will tell the user about lack of support
            }
            // this logic is put to a separate method to avoid any assembly loading issues on non Windows systems
            string version = FrameworkVersionHelper.GetLatestNetDeveloperPackVersion();

            return(Toolchains.TryGetValue(version, out var toolchain) ? toolchain : Default);
        }