Use product version in RuntimeInformation.FrameworkDescription (dotnet/corefx#35516)
authorJan Kotas <jkotas@microsoft.com>
Sat, 23 Feb 2019 05:07:03 +0000 (21:07 -0800)
committerGitHub <noreply@github.com>
Sat, 23 Feb 2019 05:07:03 +0000 (21:07 -0800)
* Use product version in RuntimeInformation.FrameworkDescription

* Include FrameworkDescription in the Assert

* Strip the git hash in the fallback

Commit migrated from https://github.com/dotnet/corefx/commit/db95b37fa3218e20ff639b232a41202b24ddcb39

src/libraries/System.Runtime.InteropServices.RuntimeInformation/src/System/Runtime/InteropServices/RuntimeInformation/RuntimeInformation.cs
src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/DescriptionNameTests.cs

index 6485879..1d180e5 100644 (file)
@@ -23,9 +23,20 @@ namespace System.Runtime.InteropServices
             {
                 if (s_frameworkDescription == null)
                 {
-                    AssemblyFileVersionAttribute attr = (AssemblyFileVersionAttribute)(typeof(object).GetTypeInfo().Assembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute)));
-                    Debug.Assert(attr != null);
-                    s_frameworkDescription = $"{FrameworkName} {attr.Version}";
+                    string versionString = (string)AppContext.GetData("FX_PRODUCT_VERSION");
+
+                    if (versionString == null)
+                    {
+                        // Use AssemblyInformationalVersionAttribute as fallback if the exact product version is not specified by the host
+                        versionString = typeof(object).Assembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
+
+                        // Strip the git hash if there is one
+                        int plusIndex = versionString.IndexOf('+');
+                        if (plusIndex != -1)
+                            versionString = versionString.Substring(0, plusIndex);
+                    }
+
+                    s_frameworkDescription = $"{FrameworkName} {versionString}";
                 }
 
                 return s_frameworkDescription;
index 59f49dd..821c112 100644 (file)
@@ -44,31 +44,17 @@ namespace System.Runtime.InteropServices.RuntimeInformationTests
 
         [Fact]
         [SkipOnTargetFramework(~TargetFrameworkMonikers.Netcoreapp)]
-        public void VerifyRuntimeDebugNameOnNetCoreApp()
+        public void VerifyRuntimeNameOnNetCoreApp()
         {
-            AssemblyFileVersionAttribute attr = (AssemblyFileVersionAttribute)(typeof(object).GetTypeInfo().Assembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute)));
-            string expected = string.Format(".NET Core {0}", attr.Version);
-            Assert.Equal(expected, RuntimeInformation.FrameworkDescription);
+            Assert.True(RuntimeInformation.FrameworkDescription.StartsWith(".NET Core"), RuntimeInformation.FrameworkDescription);
             Assert.Same(RuntimeInformation.FrameworkDescription, RuntimeInformation.FrameworkDescription);
         }
 
         [Fact]
-        [SkipOnTargetFramework(~TargetFrameworkMonikers.NetFramework)]
-        public void VerifyRuntimeDebugNameOnNetFramework()
+        [SkipOnTargetFramework(~TargetFrameworkMonikers.UapAot)]
+        public void VerifyRuntimeNameOnNetNative()
         {
-            AssemblyFileVersionAttribute attr = (AssemblyFileVersionAttribute)(typeof(object).GetTypeInfo().Assembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute)));
-            string expected = string.Format(".NET Framework {0}", attr.Version);
-            Assert.Equal(expected, RuntimeInformation.FrameworkDescription);
-            Assert.Same(RuntimeInformation.FrameworkDescription, RuntimeInformation.FrameworkDescription);
-        }
-
-        [Fact]
-        [SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework | TargetFrameworkMonikers.Netcoreapp)]
-        public void VerifyRuntimeDebugNameOnNetCoreUwp()
-        {
-            AssemblyFileVersionAttribute attr = (AssemblyFileVersionAttribute)(typeof(object).GetTypeInfo().Assembly.GetCustomAttribute(typeof(AssemblyFileVersionAttribute)));
-            string expected = string.Format(PlatformDetection.IsNetNative ? ".NET Native {0}" : ".NET Core {0}", attr.Version);
-            Assert.Equal(expected, RuntimeInformation.FrameworkDescription);
+            Assert.True(RuntimeInformation.FrameworkDescription.StartsWith(".NET Native"), RuntimeInformation.FrameworkDescription);
             Assert.Same(RuntimeInformation.FrameworkDescription, RuntimeInformation.FrameworkDescription);
         }
 
@@ -87,32 +73,32 @@ namespace System.Runtime.InteropServices.RuntimeInformationTests
             Assert.False(RuntimeInformation.OSDescription.EndsWith(" "));
         }
 
-        [Fact, PlatformSpecific(TestPlatforms.Windows)]  // Checks Windows debug name in RuntimeInformation
-        public void VerifyWindowsDebugName()
+        [Fact, PlatformSpecific(TestPlatforms.Windows)]  // Checks Windows name in RuntimeInformation
+        public void VerifyWindowsName()
         {
             Assert.Contains("windows", RuntimeInformation.OSDescription, StringComparison.OrdinalIgnoreCase);
         }
 
-        [Fact, PlatformSpecific(TestPlatforms.Linux)]  // Checks Linux debug name in RuntimeInformation
-        public void VerifyLinuxDebugName()
+        [Fact, PlatformSpecific(TestPlatforms.Linux)]  // Checks Linux name in RuntimeInformation
+        public void VerifyLinuxName()
         {
             Assert.Contains("linux", RuntimeInformation.OSDescription, StringComparison.OrdinalIgnoreCase);
         }
 
-        [Fact, PlatformSpecific(TestPlatforms.NetBSD)]  // Checks NetBSD debug name in RuntimeInformation
-        public void VerifyNetBSDDebugName()
+        [Fact, PlatformSpecific(TestPlatforms.NetBSD)]  // Checks NetBSD name in RuntimeInformation
+        public void VerifyNetBSDName()
         {
             Assert.Contains("netbsd", RuntimeInformation.OSDescription, StringComparison.OrdinalIgnoreCase);
         }
 
-        [Fact, PlatformSpecific(TestPlatforms.FreeBSD)]  // Checks FreeBSD debug name in RuntimeInformation
-        public void VerifyFreeBSDDebugName()
+        [Fact, PlatformSpecific(TestPlatforms.FreeBSD)]  // Checks FreeBSD name in RuntimeInformation
+        public void VerifyFreeBSDName()
         {
             Assert.Contains("FreeBSD", RuntimeInformation.OSDescription, StringComparison.OrdinalIgnoreCase);
         }
 
-        [Fact, PlatformSpecific(TestPlatforms.OSX)]  // Checks OSX debug name in RuntimeInformation
-        public void VerifyOSXDebugName()
+        [Fact, PlatformSpecific(TestPlatforms.OSX)]  // Checks OSX name in RuntimeInformation
+        public void VerifyOSXName()
         {
             Assert.Contains("darwin", RuntimeInformation.OSDescription, StringComparison.OrdinalIgnoreCase);
         }