/
NetCoreAppSettings.cs
84 lines (75 loc) · 2.96 KB
/
NetCoreAppSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System.Reflection;
using JetBrains.Annotations;
namespace BenchmarkDotNet.Toolchains.DotNetCli
{
/// <summary>
/// custom settings used in the auto-generated project.json / .csproj file
/// </summary>
[PublicAPI]
public class NetCoreAppSettings
{
[PublicAPI] public static readonly NetCoreAppSettings NetCoreApp11 = new NetCoreAppSettings("netcoreapp1.1", null, ".NET Core 1.1");
[PublicAPI] public static readonly NetCoreAppSettings NetCoreApp12 = new NetCoreAppSettings("netcoreapp1.2", null, ".NET Core 1.0");
[PublicAPI] public static readonly NetCoreAppSettings NetCoreApp20 = new NetCoreAppSettings("netcoreapp2.0", null, ".NET Core 2.0");
private static NetCoreAppSettings Default =>
#if NETCOREAPP2_0
NetCoreApp20;
#else
NetCoreApp11;
#endif
/// <summary>
/// <param name="targetFrameworkMoniker">
/// sample values: netcoreapp1.1, netcoreapp1.2, netcoreapp2.0
/// </param>
/// <param name="runtimeFrameworkVersion">
/// used in the auto-generated .csproj file
/// simply ignored if null or empty
/// </param>
/// <param name="name">display name used for showing the results</param>
/// </summary>
[PublicAPI]
public NetCoreAppSettings(
string targetFrameworkMoniker,
string runtimeFrameworkVersion,
string name)
{
TargetFrameworkMoniker = targetFrameworkMoniker;
RuntimeFrameworkVersion = runtimeFrameworkVersion;
Name = name;
}
/// <summary>
/// sample values: netcoreapp1.1, netcoreapp2.0, netcoreapp2.1
/// </summary>
public string TargetFrameworkMoniker { get; }
public string RuntimeFrameworkVersion { get; }
/// <summary>
/// display name used for showing the results
/// </summary>
public string Name { get; }
internal static NetCoreAppSettings GetCurrentVersion()
{
#if CLASSIC
return Default;
#else
try
{
// it's an experimental way to determine the .NET Core Runtime version
// based on dev packages available at https://dotnet.myget.org/feed/dotnet-core/package/nuget/Microsoft.NETCore.App
var assembly = Assembly.Load(new AssemblyName("System.Runtime"));
if (assembly.FullName.Contains("Version=4.1.1"))
return NetCoreApp11;
// the problem is that both netcoreapp1.2 and netcoreapp2.0 have
// "System.Runtime Version=1.2.0.0".
// 2.0 was officialy announced name, so let's bet on it (1.2 was probably an internal dev thing)
if (assembly.FullName.Contains("Version=4.2"))
return NetCoreApp20;
}
catch
{
return Default;
}
return Default;
#endif
}
}
}