15
15
#if NETCOREAPP
16
16
using System . Text ;
17
17
using Internal . Microsoft . Extensions . DependencyModel ;
18
- using InternalRuntimeEnvironment = Internal . Microsoft . DotNet . PlatformAbstractions . RuntimeEnvironment ;
19
18
#endif
20
19
21
20
namespace Xunit . Runner . VisualStudio
@@ -251,9 +250,13 @@ void DiscoverTests<TVisitor>(
251
250
var fileName = Path . GetFileNameWithoutExtension ( assemblyFileName ) ;
252
251
var shadowCopy = configuration . ShadowCopyOrDefault ;
253
252
var diagnosticSink = DiagnosticMessageSink . ForDiagnostics ( logger , fileName , configuration . DiagnosticMessagesOrDefault ) ;
253
+ var appDomain = configuration . AppDomain ?? AppDomainDefaultBehavior ;
254
254
255
- using var framework = new XunitFrontController ( AppDomainDefaultBehavior , assemblyFileName , shadowCopy : shadowCopy , diagnosticMessageSink : MessageSinkAdapter . Wrap ( diagnosticSink ) ) ;
256
- if ( ! DiscoverTestsInSource ( framework , logger , testPlatformContext , runSettings , visitorFactory , visitComplete , assemblyFileName , shadowCopy , configuration ) )
255
+ if ( runSettings . DisableAppDomain )
256
+ appDomain = AppDomainSupport . Denied ;
257
+
258
+ using var framework = new XunitFrontController ( appDomain , assemblyFileName , shadowCopy : shadowCopy , diagnosticMessageSink : MessageSinkAdapter . Wrap ( diagnosticSink ) ) ;
259
+ if ( ! DiscoverTestsInSource ( framework , logger , testPlatformContext , runSettings , visitorFactory , visitComplete , assemblyFileName , shadowCopy , configuration , appDomain ) )
257
260
break ;
258
261
}
259
262
}
@@ -272,7 +275,8 @@ bool DiscoverTestsInSource<TVisitor>(
272
275
Action < string , ITestFrameworkDiscoverer , ITestFrameworkDiscoveryOptions , TVisitor > ? visitComplete ,
273
276
string assemblyFileName ,
274
277
bool shadowCopy ,
275
- TestAssemblyConfiguration configuration )
278
+ TestAssemblyConfiguration configuration ,
279
+ AppDomainSupport appDomain )
276
280
where TVisitor : IVsDiscoverySink , IDisposable
277
281
{
278
282
if ( cancelled )
@@ -297,7 +301,7 @@ bool DiscoverTestsInSource<TVisitor>(
297
301
298
302
using var visitor = visitorFactory ( assemblyFileName , framework , discoveryOptions ) ;
299
303
var totalTests = 0 ;
300
- var usingAppDomains = framework . CanUseAppDomains && AppDomainDefaultBehavior != AppDomainSupport . Denied ;
304
+ var usingAppDomains = framework . CanUseAppDomains && appDomain != AppDomainSupport . Denied ;
301
305
reporterMessageHandler . OnMessage ( new TestAssemblyDiscoveryStarting ( assembly , usingAppDomains , shadowCopy , discoveryOptions ) ) ;
302
306
303
307
try
@@ -469,7 +473,8 @@ void RunTestsInAssembly(
469
473
} ,
470
474
assemblyFileName ,
471
475
shadowCopy ,
472
- configuration
476
+ configuration ,
477
+ appDomain
473
478
) ;
474
479
475
480
if ( assemblyDiscoveredInfo == null || assemblyDiscoveredInfo . DiscoveredTestCases == null || ! assemblyDiscoveredInfo . DiscoveredTestCases . Any ( ) )
0 commit comments