@@ -20,7 +20,9 @@ public static class FakesUtilities
20
20
{
21
21
private const string ConfiguratorAssemblyQualifiedName = "Microsoft.VisualStudio.TestPlatform.Fakes.FakesDataCollectorConfiguration" ;
22
22
23
- private const string ConfiguratorMethodName = "GetDataCollectorSettingsOrDefault" ;
23
+ private const string NetFrameworkConfiguratorMethodName = "GetDataCollectorSettingsOrDefault" ;
24
+
25
+ private const string CrossPlatformConfiguratorMethodName = "GetCrossPlatformDataCollectorSettings" ;
24
26
25
27
private const string FakesConfiguratorAssembly = "Microsoft.VisualStudio.TestPlatform.Fakes, Version=16.0.0.0, Culture=neutral" ;
26
28
@@ -50,17 +52,44 @@ public static string GenerateFakesSettingsForRunConfiguration(string[] sources,
50
52
doc . Load ( xmlReader ) ;
51
53
}
52
54
53
- return ! TryAddFakesDataCollectorSettings ( doc , sources , GetFramework ( runSettingsXml ) )
54
- ? runSettingsXml
55
- : doc . OuterXml ;
55
+ var frameworkVersion = GetFramework ( runSettingsXml ) ;
56
+ if ( frameworkVersion == null )
57
+ {
58
+ return runSettingsXml ;
59
+ }
60
+
61
+ return TryAddFakesDataCollectorSettings ( doc , sources , ( FrameworkVersion ) frameworkVersion )
62
+ ? doc . OuterXml
63
+ : runSettingsXml ;
56
64
}
57
65
58
- private static FrameworkVersion GetFramework ( string runSettingsXml )
66
+ /// <summary>
67
+ /// returns FrameworkVersion contained in the runsettingsXML
68
+ /// </summary>
69
+ /// <param name="runSettingsXml"></param>
70
+ /// <returns></returns>
71
+ private static FrameworkVersion ? GetFramework ( string runSettingsXml )
59
72
{
60
- var config = XmlRunSettingsUtilities . GetRunConfigurationNode ( runSettingsXml ) ;
61
- #pragma warning disable CS0618 // Type or member is obsolete
62
- return config . TargetFrameworkVersion ;
63
- #pragma warning restore CS0618 // Type or member is obsolete
73
+ // We assume that only .NET Core, .NET Standard, or .NET Framework projects can have fakes.
74
+ var targetFramework = XmlRunSettingsUtilities . GetRunConfigurationNode ( runSettingsXml ) ? . TargetFramework ;
75
+
76
+ if ( targetFramework == null )
77
+ {
78
+ return null ;
79
+ }
80
+
81
+ // Since there are no FrameworkVersion values for .Net Core 2.0 +, we check TargetFramework instead
82
+ // and default to FrameworkCore10 for .Net Core
83
+ if ( targetFramework . Name . IndexOf ( "netstandard" , StringComparison . OrdinalIgnoreCase ) >= 0 ||
84
+ targetFramework . Name . IndexOf ( "netcoreapp" , StringComparison . OrdinalIgnoreCase ) >= 0 )
85
+ {
86
+ return FrameworkVersion . FrameworkCore10 ;
87
+ }
88
+
89
+ // Since the Datacollector is separated on the NetFramework/NetCore line, any value of NETFramework
90
+ // can be passed along to the fakes data collector configuration creator.
91
+ // We default to Framework40 to preserve back compat
92
+ return FrameworkVersion . Framework40 ;
64
93
}
65
94
66
95
/// <summary>
@@ -85,11 +114,11 @@ private static bool TryAddFakesDataCollectorSettings(
85
114
// using the CLRIE profiler, and the old involves using the Intellitrace profiler (which isn't supported in
86
115
// .NET Core scenarios). The old API still exists for fallback measures.
87
116
88
- var newConfigurator = TryGetFakesNewDataCollectorConfigurator ( ) ;
89
- if ( newConfigurator != null )
117
+ var crossPlatformConfigurator = TryGetFakesCrossPlatformDataCollectorConfigurator ( ) ;
118
+ if ( crossPlatformConfigurator != null )
90
119
{
91
120
var sourceTFMMap = CreateDictionary ( sources , framework ) ;
92
- var fakesSettings = newConfigurator ( sourceTFMMap ) ;
121
+ var fakesSettings = crossPlatformConfigurator ( sourceTFMMap ) ;
93
122
// if no fakes, return settings unchanged
94
123
if ( fakesSettings == null )
95
124
{
@@ -132,14 +161,14 @@ private static bool AddFallbackFakesSettings(
132
161
return false ;
133
162
}
134
163
135
- Func < IEnumerable < string > , string > oldConfigurator = TryGetFakesDataCollectorConfigurator ( ) ;
136
- if ( oldConfigurator == null )
164
+ Func < IEnumerable < string > , string > netFrameworkConfigurator = TryGetNetFrameworkFakesDataCollectorConfigurator ( ) ;
165
+ if ( netFrameworkConfigurator == null )
137
166
{
138
167
return false ;
139
168
}
140
169
141
170
// if no fakes, return settings unchanged
142
- var fakesConfiguration = oldConfigurator ( sources ) ;
171
+ var fakesConfiguration = netFrameworkConfigurator ( sources ) ;
143
172
if ( fakesConfiguration == null )
144
173
{
145
174
return false ;
@@ -184,14 +213,14 @@ private static void EnsureSettingsNode(XmlDocument settings, TestRunSettings set
184
213
}
185
214
}
186
215
187
- private static Func < IEnumerable < string > , string > TryGetFakesDataCollectorConfigurator ( )
216
+ private static Func < IEnumerable < string > , string > TryGetNetFrameworkFakesDataCollectorConfigurator ( )
188
217
{
189
218
#if NET451
190
219
try
191
220
{
192
221
Assembly assembly = Assembly . Load ( FakesConfiguratorAssembly ) ;
193
222
var type = assembly ? . GetType ( ConfiguratorAssemblyQualifiedName , false ) ;
194
- var method = type ? . GetMethod ( ConfiguratorMethodName , new Type [ ] { typeof ( IEnumerable < string > ) } ) ;
223
+ var method = type ? . GetMethod ( NetFrameworkConfiguratorMethodName , new Type [ ] { typeof ( IEnumerable < string > ) } ) ;
195
224
if ( method != null )
196
225
{
197
226
return ( Func < IEnumerable < string > , string > ) method . CreateDelegate ( typeof ( Func < IEnumerable < string > , string > ) ) ;
@@ -208,13 +237,13 @@ private static Func<IEnumerable<string>, string> TryGetFakesDataCollectorConfigu
208
237
return null ;
209
238
}
210
239
211
- private static Func < IDictionary < string , FrameworkVersion > , DataCollectorSettings > TryGetFakesNewDataCollectorConfigurator ( )
240
+ private static Func < IDictionary < string , FrameworkVersion > , DataCollectorSettings > TryGetFakesCrossPlatformDataCollectorConfigurator ( )
212
241
{
213
242
try
214
243
{
215
244
Assembly assembly = Assembly . Load ( FakesConfiguratorAssembly ) ;
216
245
var type = assembly ? . GetType ( ConfiguratorAssemblyQualifiedName , false ) ;
217
- var method = type ? . GetMethod ( ConfiguratorMethodName , new Type [ ] { typeof ( IDictionary < string , FrameworkVersion > ) } ) ;
246
+ var method = type ? . GetMethod ( CrossPlatformConfiguratorMethodName , new Type [ ] { typeof ( IDictionary < string , FrameworkVersion > ) } ) ;
218
247
if ( method != null )
219
248
{
220
249
return ( Func < IDictionary < string , FrameworkVersion > , DataCollectorSettings > ) method . CreateDelegate ( typeof ( Func < IDictionary < string , FrameworkVersion > , DataCollectorSettings > ) ) ;
0 commit comments