@@ -21,13 +21,15 @@ internal static class RuntimeInformation
21
21
22
22
internal static bool IsFullFramework => FrameworkDescription . StartsWith ( ".NET Framework" , StringComparison . OrdinalIgnoreCase ) ;
23
23
24
- internal static bool IsNetCore => FrameworkDescription . StartsWith ( ".NET Core" , StringComparison . OrdinalIgnoreCase ) && ! string . IsNullOrEmpty ( typeof ( object ) . Assembly . Location ) ;
24
+ internal static bool IsNetCore
25
+ => ( ( Environment . Version . Major >= 5 ) || FrameworkDescription . StartsWith ( ".NET Core" , StringComparison . OrdinalIgnoreCase ) )
26
+ && ! string . IsNullOrEmpty ( typeof ( object ) . Assembly . Location ) ;
25
27
26
28
/// <summary>
27
29
/// "The north star for CoreRT is to be a flavor of .NET Core" -> CoreRT reports .NET Core everywhere.
28
30
/// </summary>
29
31
internal static bool IsCoreRT
30
- => FrameworkDescription . StartsWith ( ".NET Core" , StringComparison . OrdinalIgnoreCase )
32
+ => ( ( Environment . Version . Major >= 5 ) || FrameworkDescription . StartsWith ( ".NET Core" , StringComparison . OrdinalIgnoreCase ) )
31
33
&& string . IsNullOrEmpty ( typeof ( object ) . Assembly . Location ) ; // but it's merged to a single .exe and .Location returns null here ;)
32
34
33
35
internal static bool IsRunningInContainer => string . Equals ( Environment . GetEnvironmentVariable ( "DOTNET_RUNNING_IN_CONTAINER" ) , "true" ) ;
@@ -110,27 +112,7 @@ internal static string GetFullFrameworkVersion()
110
112
111
113
internal static string MapToReleaseVersion ( string servicingVersion )
112
114
{
113
- // the following code assumes that .NET 4.5 is the oldest supported version
114
- if ( string . Compare ( servicingVersion , "4.5.1" ) < 0 )
115
- {
116
- return "4.5" ;
117
- }
118
-
119
- if ( string . Compare ( servicingVersion , "4.5.2" ) < 0 )
120
- {
121
- return "4.5.1" ;
122
- }
123
-
124
- if ( string . Compare ( servicingVersion , "4.6" ) < 0 )
125
- {
126
- return "4.5.2" ;
127
- }
128
-
129
- if ( string . Compare ( servicingVersion , "4.6.1" ) < 0 )
130
- {
131
- return "4.6" ;
132
- }
133
-
115
+ // the following code assumes that .NET 4.6.1 is the oldest supported version
134
116
if ( string . Compare ( servicingVersion , "4.6.2" ) < 0 )
135
117
{
136
118
return "4.6.1" ;
@@ -161,15 +143,30 @@ internal static string MapToReleaseVersion(string servicingVersion)
161
143
162
144
internal static string GetNetCoreVersion ( )
163
145
{
164
- string runtimeVersion = TryGetCoreRuntimeVersion ( out var version ) ? version . ToString ( ) : "?" ;
146
+ if ( TryGetCoreRuntimeVersion ( out var version ) && version >= new Version ( 5 , 0 ) )
147
+ {
148
+ return $ ".NET { version } ";
149
+ }
150
+ else
151
+ {
152
+ string runtimeVersion = version != default ? version . ToString ( ) : "?" ;
165
153
166
- return $ ".NET Core { runtimeVersion } ";
154
+ return $ ".NET Core { runtimeVersion } ";
155
+ }
167
156
}
168
157
169
158
internal static bool TryGetCoreRuntimeVersion ( out Version version )
170
159
{
171
160
// we can't just use System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription
172
161
// because it can be null and it reports versions like 4.6.* for .NET Core 2.*
162
+
163
+ // for .NET 5+ we can use Environment.Version
164
+ if ( Environment . Version . Major >= 5 )
165
+ {
166
+ version = Environment . Version ;
167
+ return true ;
168
+ }
169
+
173
170
string runtimeDirectory = System . Runtime . InteropServices . RuntimeEnvironment . GetRuntimeDirectory ( ) ;
174
171
if ( TryGetVersionFromRuntimeDirectory ( runtimeDirectory , out version ) )
175
172
{
0 commit comments