diff --git a/src/xunit.runner.visualstudio/VsTestRunner.cs b/src/xunit.runner.visualstudio/VsTestRunner.cs index 4d396c9..4c79e6c 100644 --- a/src/xunit.runner.visualstudio/VsTestRunner.cs +++ b/src/xunit.runner.visualstudio/VsTestRunner.cs @@ -8,7 +8,6 @@ using System.Threading; using Microsoft.VisualStudio.TestPlatform.ObjectModel; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Adapter; -using Microsoft.VisualStudio.TestPlatform.ObjectModel.Host; using Microsoft.VisualStudio.TestPlatform.ObjectModel.Logging; using Xunit.Abstractions; using Xunit.Internal; @@ -229,11 +228,8 @@ void DiscoverTests( RemotingUtility.CleanUpRegisteredChannels(); var internalDiagnosticsMessageSink = DiagnosticMessageSink.ForInternalDiagnostics(logger, runSettings.InternalDiagnosticMessages ?? false); - var wrappedInternalDiagnosticsMessageSink = MessageSinkAdapter.Wrap(internalDiagnosticsMessageSink); - - using var _1 = AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), wrappedInternalDiagnosticsMessageSink); - using var _2 = AssemblyHelper.SubscribeResolveForAssembly(typeof(ITestRuntimeProvider), wrappedInternalDiagnosticsMessageSink); + using var _ = AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), MessageSinkAdapter.Wrap(internalDiagnosticsMessageSink)); foreach (var assemblyFileNameCanBeWithoutAbsolutePath in sources) { var assembly = new XunitProjectAssembly { AssemblyFilename = GetAssemblyFileName(assemblyFileNameCanBeWithoutAbsolutePath) }; @@ -389,18 +385,17 @@ void RunTests( var reporter = GetRunnerReporter(logger, runSettings, runInfos.Select(ari => ari.Assembly.AssemblyFilename).ToList()); using var reporterMessageHandler = MessageSinkWithTypesAdapter.Wrap(reporter.CreateMessageHandler(new VisualStudioRunnerLogger(logger))); using var internalDiagnosticsMessageSink = DiagnosticMessageSink.ForInternalDiagnostics(logger, runSettings.InternalDiagnosticMessages ?? false); - var wrappedInternalDiagnosticsMessageSink = MessageSinkAdapter.Wrap(internalDiagnosticsMessageSink); - - using var _1 = AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), wrappedInternalDiagnosticsMessageSink); - using var _2 = AssemblyHelper.SubscribeResolveForAssembly(typeof(ITestRuntimeProvider), wrappedInternalDiagnosticsMessageSink); - if (parallelizeAssemblies) - runInfos - .Select(runInfo => RunTestsInAssemblyAsync(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo)) - .ToList() - .ForEach(@event => @event.WaitOne()); - else - runInfos.ForEach(runInfo => RunTestsInAssembly(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo)); + using (AssemblyHelper.SubscribeResolveForAssembly(typeof(VsTestRunner), MessageSinkAdapter.Wrap(internalDiagnosticsMessageSink))) + { + if (parallelizeAssemblies) + runInfos + .Select(runInfo => RunTestsInAssemblyAsync(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo)) + .ToList() + .ForEach(@event => @event.WaitOne()); + else + runInfos.ForEach(runInfo => RunTestsInAssembly(runContext, frameworkHandle, logger, testPlatformContext, runSettings, reporterMessageHandler, runInfo)); + } } catch (Exception ex) { diff --git a/src/xunit.runner.visualstudio/xunit.runner.visualstudio.nuspec b/src/xunit.runner.visualstudio/xunit.runner.visualstudio.nuspec index 4a3c0d7..6549723 100644 --- a/src/xunit.runner.visualstudio/xunit.runner.visualstudio.nuspec +++ b/src/xunit.runner.visualstudio/xunit.runner.visualstudio.nuspec @@ -16,7 +16,9 @@ true - + + +