@@ -19,15 +19,19 @@ internal static partial class AppContextDefaultValues
19
19
{
20
20
public static void PopulateDefaultValues ( )
21
21
{
22
- string platformIdentifier , profile ;
23
- int version ;
24
-
25
- ParseTargetFrameworkName ( out platformIdentifier , out profile , out version ) ;
22
+ #if NETFX
23
+ // Get Target Framework information
24
+ ParseTargetFrameworkName ( out string platformIdentifier , out string profile , out int version ) ;
26
25
27
26
// Call into each library to populate their default switches
28
27
PopulateDefaultValuesPartial ( platformIdentifier , profile , version ) ;
28
+ #else
29
+ // Call into each library to populate their default switches
30
+ // ".NETCoreApp,Version=v3.0"
31
+ PopulateDefaultValuesPartial ( ".NETCoreApp" , string . Empty , 30000 ) ;
32
+ #endif
29
33
}
30
-
34
+ #if NETFX
31
35
/// <summary>
32
36
/// We have this separate method for getting the parsed elements out of the TargetFrameworkName so we can
33
37
/// more easily support this on other platforms.
@@ -67,29 +71,10 @@ private static void ParseTargetFrameworkName(out string identifier, out string p
67
71
/// <summary>
68
72
/// This is equivalent to calling <code>AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName</code>
69
73
/// </summary>
70
- /// <remarks>
71
- /// <code>AppDomain.CurrentDomain.SetupInformation</code> is not available until .NET Core 3.0, but we
72
- /// have a need to run this code in .NET Core 2.2, we attempt to obtain this information via Reflection.
73
- /// </remarks>
74
74
/// <returns>TargetFrameworkMoniker on .NET Framework and .NET Core 3.0+; null on .NET Core 2.2 or older runtimes</returns>
75
75
private static string GetTargetFrameworkMoniker ( )
76
76
{
77
- try
78
- {
79
- var pSetupInformation = typeof ( AppDomain ) . GetProperty ( "SetupInformation" ) ;
80
- object appDomainSetup = pSetupInformation ? . GetValue ( AppDomain . CurrentDomain ) ;
81
- Type tAppDomainSetup = Type . GetType ( "System.AppDomainSetup" ) ;
82
- var pTargetFrameworkName = tAppDomainSetup ? . GetProperty ( "TargetFrameworkName" ) ;
83
-
84
- return
85
- appDomainSetup != null ?
86
- pTargetFrameworkName ? . GetValue ( appDomainSetup ) as string :
87
- null ;
88
- }
89
- catch ( Exception )
90
- {
91
- return null ;
92
- }
77
+ return AppContext . TargetFrameworkName ;
93
78
}
94
79
95
80
// This code was a constructor copied from the FrameworkName class, which is located in System.dll.
@@ -196,7 +181,7 @@ private static bool TryParseFrameworkName(String frameworkName, out String ident
196
181
197
182
return true ;
198
183
}
199
-
184
+ #endif
200
185
// This is a partial method. Platforms (such as Desktop) can provide an implementation of it that will read override value
201
186
// from whatever mechanism is available on that platform. If no implementation is provided, the compiler is going to remove the calls
202
187
// to it from the code
0 commit comments