Skip to content

use Environment.Version to determine .NET 5+ versions #1580

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/BenchmarkDotNet/Environments/Runtimes/CoreRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ internal static bool TryGetVersion(out Version version)
// we can't just use System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription
// because it can be null and it reports versions like 4.6.* for .NET Core 2.*

// for .NET 5+ we can use Environment.Version
if (Environment.Version.Major >= 5)
{
version = Environment.Version;
return true;
}

string runtimeDirectory = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
if (TryGetVersionFromRuntimeDirectory(runtimeDirectory, out version))
{
Expand All @@ -89,6 +96,9 @@ internal static bool TryGetVersion(out Version version)
return true;
}

// it's OK to use this method only after checking the previous ones
// because we might have a benchmark app build for .NET Core X but executed using CoreRun Y
// example: -f netcoreapp3.1 --corerun $omittedForBrevity\Microsoft.NETCore.App\6.0.0\CoreRun.exe - built as 3.1, run as 6.0 (#1576)
string frameworkName = Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName;
if (TryGetVersionFromFrameworkName(frameworkName, out version))
{
Expand Down