Ejemplo n.º 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}"));
            }
        }
Ejemplo n.º 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);
        }
        internal static string GetRuntimeVersion()
        {
            if (IsMono)
            {
                var monoRuntimeType = Type.GetType("Mono.Runtime");
                var monoDisplayName = monoRuntimeType?.GetMethod("GetDisplayName", BindingFlags.NonPublic | BindingFlags.Static);
                if (monoDisplayName != null)
                {
                    string version = monoDisplayName.Invoke(null, null)?.ToString();
                    if (version != null)
                    {
                        int bracket1 = version.IndexOf('('), bracket2 = version.IndexOf(')');
                        if (bracket1 != -1 && bracket2 != -1)
                        {
                            string comment      = version.Substring(bracket1 + 1, bracket2 - bracket1 - 1);
                            var    commentParts = comment.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            if (commentParts.Length > 2)
                            {
                                version = version.Substring(0, bracket1) + "(" + commentParts[0] + " " + commentParts[1] + ")";
                            }
                        }
                    }

                    return("Mono " + version);
                }
            }
            else if (IsFullFramework)
            {
                string frameworkVersion = FrameworkVersionHelper.GetCurrentNetFrameworkVersion();
                string clrVersion       = Environment.Version.ToString();
                return($".NET Framework {frameworkVersion} (CLR {clrVersion})");
            }
            else if (IsNetCore)
            {
                string runtimeVersion = GetNetCoreVersion() ?? "?";

                var coreclrAssemblyInfo = FileVersionInfo.GetVersionInfo(typeof(object).GetTypeInfo().Assembly.Location);
                var corefxAssemblyInfo  = FileVersionInfo.GetVersionInfo(typeof(Regex).GetTypeInfo().Assembly.Location);

                return($".NET Core {runtimeVersion} (CoreCLR {coreclrAssemblyInfo.FileVersion}, CoreFX {corefxAssemblyInfo.FileVersion})");
            }
            else if (IsCoreRT)
            {
                return(FrameworkDescription.Replace("Core ", "CoreRT "));
            }

            return(Unknown);
        }
Ejemplo n.º 4
0
 public void ServicingVersionsAreMappedToCorrespondingReleaseVersions(string servicingVersion, string expectedReleaseVersion)
 {
     Assert.Equal(expectedReleaseVersion, FrameworkVersionHelper.MapToReleaseVersion(servicingVersion));
 }
        internal static string GetRuntimeVersion()
        {
            if (IsMono)
            {
                var monoRuntimeType = Type.GetType("Mono.Runtime");
                var monoDisplayName = monoRuntimeType?.GetMethod("GetDisplayName", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
                if (monoDisplayName != null)
                {
                    string version = monoDisplayName.Invoke(null, null)?.ToString();
                    if (version != null)
                    {
                        int bracket1 = version.IndexOf('('), bracket2 = version.IndexOf(')');
                        if (bracket1 != -1 && bracket2 != -1)
                        {
                            string comment      = version.Substring(bracket1 + 1, bracket2 - bracket1 - 1);
                            var    commentParts = comment.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                            if (commentParts.Length > 2)
                            {
                                version = version.Substring(0, bracket1) + "(" + commentParts[0] + " " + commentParts[1] + ")";
                            }
                        }
                    }

                    return("Mono " + version);
                }
            }
            else if (IsFullFramework)
            {
                return(FrameworkVersionHelper.GetFrameworkDescription());
            }
            else if (IsWasm)
            {
                // code copied from https://github.com/dotnet/runtime/blob/2c573b59aaaf3fd17e2ecab95ad3769f195d2dbc/src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.cs#L20-L30
                string versionString = typeof(object).Assembly.GetCustomAttribute <AssemblyInformationalVersionAttribute>()?.InformationalVersion;

                // Strip the git hash if there is one
                if (versionString != null)
                {
                    int plusIndex = versionString.IndexOf('+');
                    if (plusIndex != -1)
                    {
                        versionString = versionString.Substring(0, plusIndex);
                    }
                }

                return($".NET Core (Mono) {versionString}");
            }
            else if (IsNetCore)
            {
                var coreclrAssemblyInfo = FileVersionInfo.GetVersionInfo(typeof(object).GetTypeInfo().Assembly.Location);
                var corefxAssemblyInfo  = FileVersionInfo.GetVersionInfo(typeof(Regex).GetTypeInfo().Assembly.Location);

                if (CoreRuntime.TryGetVersion(out var version) && version >= new Version(5, 0))
                {
                    // after the merge of dotnet/corefx and dotnet/coreclr into dotnet/runtime the version should always be the same
                    Debug.Assert(coreclrAssemblyInfo.FileVersion == corefxAssemblyInfo.FileVersion);

                    return($".NET {version} ({coreclrAssemblyInfo.FileVersion})");
                }
                else
                {
                    string runtimeVersion = version != default ? version.ToString() : "?";

                    return($".NET Core {runtimeVersion} (CoreCLR {coreclrAssemblyInfo.FileVersion}, CoreFX {corefxAssemblyInfo.FileVersion})");
                }
            }
 static DotNetrameworks()
 {
     AllFrameworkVersions = FrameworkVersionHelper.GetVersionFromRegistry();
     _ver = FindLatestFramework();
 }