Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Change Environment.Version to return product version
Browse files Browse the repository at this point in the history
- Contributes to https://github.com/dotnet/corefx/issues/31099
- Use AssemblyInformationalVersion attribute as fallback
  • Loading branch information
jkotas committed Feb 20, 2019
1 parent d98d827 commit 183d60b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
13 changes: 13 additions & 0 deletions src/System.Private.CoreLib/System.Private.CoreLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@
<SkipCommonResourcesIncludes>true</SkipCommonResourcesIncludes>
<DocumentationFile>$(OutputPath)$(MSBuildProjectName).xml</DocumentationFile>
</PropertyGroup>

<!-- Approximate Arcade version string https://github.com/dotnet/arcade/blob/master/Documentation/CorePackages/Versioning.md -->
<!-- This workaround should be removed once CoreCLR repo is updated to use Arcade -->
<PropertyGroup>
<InformationalVersion>$(VersionPrefix)</InformationalVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(PreReleaseLabel)' != ''">
<InformationalVersion>$(InformationalVersion)-$(PreReleaseLabel).$(BuildNumberMajor).$(BuildNumberMinor)</InformationalVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(LatestCommit)' != ''">
<InformationalVersion>$(InformationalVersion)+$(LatestCommit)</InformationalVersion>
</PropertyGroup>

<!-- Add Serviceable attribute to the project's metadata -->
<ItemGroup>
<AssemblyMetadata Include="Serviceable">
Expand Down
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
4 changes: 4 additions & 0 deletions tests/CoreFX/CoreFX.issues.json
Original file line number Diff line number Diff line change
Expand Up @@ -823,6 +823,10 @@
"name": "System.Tests.MathFTests.Min",
"reason": "https://github.com/dotnet/coreclr/pull/20912"
},
{
"name": "System.Tests.EnvironmentTests.Version_MatchesFixedVersion",
"reason": "outdated"
},
]
}
},
Expand Down

0 comments on commit 183d60b

Please sign in to comment.