Skip to content

Commit

Permalink
Change Environment.Version to return product version (dotnet/coreclr#…
Browse files Browse the repository at this point in the history
…22664)

* Change Environment.Version to return product version

- Contributes to https://github.com/dotnet/corefx/issues/31099
- Use AssemblyInformationalVersion attribute as fallback

* Add sanity test for Environment.Version

* Disable CodeDom tests

* Fix test assembly name

Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
  • Loading branch information
jkotas authored and dotnet-bot committed Feb 23, 2019
1 parent a99bac8 commit f6eb79f
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions src/System.Private.CoreLib/shared/System/Environment.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,30 @@ 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
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;
}

ReadOnlySpan<char> versionSpan = versionString.AsSpan();

// Strip optional suffixes
int separatorIndex = versionSpan.IndexOfAny("-+ ");
if (separatorIndex != -1)
versionSpan = versionSpan.Slice(0, separatorIndex);

// Return zeros rather then failing if the version string fails to parse
return Version.TryParse(versionSpan, out Version version) ? version : new Version();
}
}

public static long WorkingSet
{
Expand Down

0 comments on commit f6eb79f

Please sign in to comment.