From 472e3b8c644debcf4b13cf638a85cc929453117d Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sat, 16 Feb 2019 18:06:45 -0800 Subject: [PATCH] Change Environment.Version to return product version Contributes to https://github.com/dotnet/corefx/issues/31099 --- .../shared/System/Environment.cs | 20 +++++++++++++++---- tests/CoreFX/CoreFX.issues.json | 4 ++++ 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/System.Private.CoreLib/shared/System/Environment.cs b/src/System.Private.CoreLib/shared/System/Environment.cs index bb99dc8eac1d..10be3c436de3 100644 --- a/src/System.Private.CoreLib/shared/System/Environment.cs +++ b/src/System.Private.CoreLib/shared/System/Environment.cs @@ -129,10 +129,22 @@ public static OperatingSystem OSVersion public static bool UserInteractive => true; - // Previously this represented the File version of mscorlib.dll. Many other libraries in the framework and outside took dependencies on the first three parts of this version - // remaining constant throughout 4.x. From 4.0 to 4.5.2 this was fine since the file version only incremented the last part. Starting with 4.6 we switched to a file versioning - // scheme that matched the product version. In order to preserve compatibility with existing libraries, this needs to be hard-coded. - public static Version Version => new Version(4, 0, 30319, 42000); + public static Version Version + { + get + { + // FX_PRODUCT_VERSION is expected to be set by the host + ReadOnlySpan versionString = ((string)AppContext.GetData("FX_PRODUCT_VERSION")).AsSpan(); + + // Strip optional suffix for previews, e.g. 3.0.0-preview-27331-3 + int dashIndex = versionString.IndexOf('-'); + if (dashIndex != -1) + versionString = versionString.Slice(0, dashIndex); + + // Return zeros rather then failing if the version string fails to parse + return Version.TryParse(versionString, out Version version) ? version : new Version(); + } + } public static long WorkingSet { diff --git a/tests/CoreFX/CoreFX.issues.json b/tests/CoreFX/CoreFX.issues.json index f50611e9b6e6..aad333db8292 100644 --- a/tests/CoreFX/CoreFX.issues.json +++ b/tests/CoreFX/CoreFX.issues.json @@ -809,6 +809,10 @@ "name": "System.Tests.MathFTests.Min", "reason": "https://github.com/dotnet/coreclr/pull/20912" }, + { + "name": "System.Tests.EnvironmentTests.Version_MatchesFixedVersion", + "reason": "outdated" + }, ] } },