@@ -146,6 +146,15 @@ private bool IsMonoRuntime {
146
146
#endif
147
147
148
148
private void PopulateRuntimeInfo ( EnvironmentInfo info ) {
149
+ #if NETSTANDARD
150
+ info . OSName = GetOSName ( RuntimeInformation . OSDescription ) ;
151
+ info . OSVersion = GetVersion ( RuntimeInformation . OSDescription ) ? . ToString ( ) ;
152
+ info . Architecture = RuntimeInformation . OSArchitecture . ToString ( ) ;
153
+ info . RuntimeVersion = GetVersion ( RuntimeInformation . FrameworkDescription ) ? . ToString ( ) ;
154
+ info . Data [ "FrameworkDescription" ] = RuntimeInformation . FrameworkDescription ;
155
+ info . Data [ "ProcessArchitecture" ] = RuntimeInformation . ProcessArchitecture ;
156
+ #endif
157
+
149
158
try {
150
159
#if NET45 || NETSTANDARD1_5
151
160
info . MachineName = Environment . MachineName ;
@@ -186,12 +195,6 @@ private void PopulateRuntimeInfo(EnvironmentInfo info) {
186
195
info . Data [ "ApplicationBasePath" ] = computerInfo . Application . ApplicationBasePath ;
187
196
info . Data [ "ApplicationName" ] = computerInfo . Application . ApplicationName ;
188
197
info . Data [ "RuntimeFramework" ] = computerInfo . Application . RuntimeFramework . FullName ;
189
-
190
- info . OSName = computerInfo . Runtime . OperatingSystem ;
191
- info . OSVersion = computerInfo . Runtime . OperatingSystemVersion ;
192
- info . Architecture = computerInfo . Runtime . RuntimeArchitecture ;
193
- info . RuntimeVersion = computerInfo . Runtime . RuntimeVersion ;
194
- info . Data [ "RuntimeType" ] = computerInfo . Runtime . RuntimeType ; // Mono, CLR, CoreCLR
195
198
#elif NET45
196
199
info . OSName = computerInfo . OSFullName ;
197
200
info . OSVersion = computerInfo . OSVersion ;
@@ -202,8 +205,35 @@ private void PopulateRuntimeInfo(EnvironmentInfo info) {
202
205
_log . FormattedInfo ( typeof ( DefaultEnvironmentInfoCollector ) , "Unable to get populate runtime info. Error message: {0}" , ex . Message ) ;
203
206
}
204
207
#endif
208
+ }
209
+
210
+ #if NETSTANDARD
211
+ private string GetOSName ( string osDescription ) {
212
+ if ( String . IsNullOrEmpty ( osDescription ) )
213
+ return null ;
214
+
215
+ var version = GetVersion ( osDescription ) ;
216
+ if ( version != null )
217
+ return osDescription . Replace ( version . ToString ( ) , version . ToString ( version . Minor == 0 ? 1 : 2 ) ) ;
218
+
219
+ return osDescription ;
220
+ }
221
+
222
+ private Version GetVersion ( string description ) {
223
+ if ( String . IsNullOrEmpty ( description ) )
224
+ return null ;
225
+
226
+ var parts = description . Split ( new [ ] { ' ' } , StringSplitOptions . RemoveEmptyEntries ) ;
227
+ if ( parts . Length > 0 ) {
228
+ Version version ;
229
+ if ( Version . TryParse ( parts [ parts . Length - 1 ] , out version ) )
230
+ return version ;
205
231
}
206
232
233
+ return null ;
234
+ }
235
+ #endif
236
+
207
237
#if NET45
208
238
private bool Is64BitOperatingSystem ( ) {
209
239
if ( IntPtr . Size == 8 ) // 64-bit programs run only on Win64
@@ -223,7 +253,7 @@ private bool Is64BitOperatingSystem() {
223
253
}
224
254
225
255
private static class KernelNativeMethods {
226
- #region Kernel32
256
+ #region Kernel32
227
257
228
258
[ DllImport ( "kernel32" , CharSet = CharSet . Unicode , SetLastError = true ) ]
229
259
public static extern IntPtr GetProcAddress ( IntPtr hModule , [ MarshalAs ( UnmanagedType . LPStr ) ] string procName ) ;
@@ -248,7 +278,7 @@ private static class KernelNativeMethods {
248
278
[ DllImport ( "kernel32.dll" ) ]
249
279
public static extern int GetCurrentThreadId ( ) ;
250
280
251
- #endregion
281
+ #endregion
252
282
253
283
public static bool MethodExists ( string moduleName , string methodName ) {
254
284
IntPtr moduleHandle = GetModuleHandle ( moduleName ) ;
0 commit comments