public static Task <VsInstance> Launch(VsHive hive, TimeSpan timeout, IDiagnostics diagnostics) { Process process = null; KillProcessJob killProcessJob = null; return(diagnostics.RunAsync("Launching Instance", async output => { try { process = VisualStudioUtil.StartProcess(hive); killProcessJob = new KillProcessJob(process); var dte = await VisualStudioUtil.GetDTE(process, timeout); var invoker = (IRemoteComInvoker)dte.GetObject("VsixTesting.Invoker"); InvokeRemote(invoker, nameof(Remote.AutoKillWhenProcessExits), Process.GetCurrentProcess().Id); killProcessJob.Release(); return new VsInstance(hive.Version, process, dte, invoker); } catch { process?.Kill(); process?.Dispose(); throw; } })); }
public static async Task Prepare(VsHive hive, IEnumerable <string> extensionsToInstall, bool resetSettings, IDiagnostics diagnostics) { await diagnostics.RunAsync("Preparing Instance", async output => { var installResult = default((int InstallCount, bool HasSettingsFile, string Output)); var invokerAssembly = Assembly.GetExecutingAssembly(); using (var invoker = new TempFile(EmbeddedResourceUtil.ExtractResource(invokerAssembly, "VsixTesting.Invoker.vsix"))) { EmbeddedResourceUtil.ApplyDateTime(invoker.Path, invokerAssembly, "VsixTesting.Invoker.vsix"); installResult = await VisualStudioUtil.InstallExtensionsAsync( hive, extensionsToInstall.Concat(new[] { invoker.Path })); output.WriteLine(installResult.Output); if (installResult.InstallCount > 0) { output.WriteLine("Clearing cache"); await VisualStudioUtil.ClearCacheAsync(hive); output.WriteLine("Updating configuration"); await VisualStudioUtil.UpdateConfigurationAsync(hive); } } if (!installResult.HasSettingsFile || resetSettings) { output.WriteLine("Resetting settings"); await VisualStudioUtil.ResetSettingsAsync(hive); } }); }
public async Task Init(CancellationTokenSource cts) { if (initialized == true) { return; } AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; diagnostics = CreateDiagnostics(cts); var installation = Installations.Value.First(i => i.ApplicationPath == InstancePath); var hive = new VsHive(installation, Settings.VsRootSuffix); await VsInstance.Prepare(hive, Settings.GetExtensionsToInstall(), Settings.VsResetSettings, diagnostics); instance = await VsInstance.Launch(hive, Settings.GetLaunchTimeout(), diagnostics); if (Debugger.IsAttached) { await VsInstance.AttachDebugger(instance.Process, Settings.VsDebugMixedMode, diagnostics); } instance.SetAssemblyResolver(TestAssemblyDirectory); rmt = instance.GetOrCreateSingletonService <Rmt>("VsixTesting.Xunit", Settings.VsSecureChannel); remoteTestAssemblyRunner = CreateRemoteTestAssemblyRunner(cts); initialized = true; }
public async Task Init(CancellationTokenSource cts) { if (initialized == true) { return; } AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; diagnostics = CreateDiagnostics(cts); if (testCases.OfType <VsTestCase>().GroupBy(c => c.Settings.SecureChannel).Count() >= 2) { throw new Exception($"All test methods sharing the same Visual Studio Instance must also use the same value for {nameof(ITestSettings.SecureChannel)}."); } var installation = Installations.Value.First(i => i.ApplicationPath == InstancePath); var hive = new VsHive(installation, Settings.RootSuffix); await VsInstance.Prepare(hive, GetExtensionsToInstall(), Settings.ResetSettings, diagnostics); instance = await VsInstance.Launch(hive, Settings.GetLaunchTimeout(), diagnostics); if (Debugger.IsAttached) { await VsInstance.AttachDebugger(instance.Process, Settings.DebugMixedMode, diagnostics); } instance.SetAssemblyResolver(TestAssemblyDirectory); rmt = instance.GetOrCreateSingletonService <Rmt>("VsixTesting.Xunit", Settings.SecureChannel); remoteTestAssemblyRunner = CreateRemoteTestAssemblyRunner(cts); initialized = true; }
public async Task LaunchAndDebug(IMessageBus messageBus, CancellationTokenSource cancellationTokenSource) { await ThreadUtil.RunOnStaThreadAsync(async() => { using (var retryFilter = new RetryMessageFilter()) { var diagnostics = new VisualDiagnostics(this, DiagnosticMessageSink, messageBus, cancellationTokenSource); var extensionsToInstall = VsInstance.GetExtensionsToInstall(ExtensionDirectories); var installation = VisualStudioUtil.FindInstallations().First(i => i.ApplicationPath == ApplicationPath); var hive = new VsHive(installation, RootSuffix); await VsInstance.Prepare(hive, extensionsToInstall, resetSettings: false, diagnostics, installInvoker: false); var process = await diagnostics.RunAsync("Launching Instance", () => Task.FromResult(VisualStudioUtil.StartProcess(hive))); if (Debugger.IsAttached) { await VsInstance.AttachDebugger(process, DebugMixedMode, diagnostics); } } }); }
public static async Task Prepare(VsHive hive, IEnumerable <string> extensionsToInstall, bool resetSettings, IDiagnostics diagnostics, bool installInvoker = true) { await diagnostics.RunAsync("Preparing Instance", async output => { var invokerAssembly = Assembly.GetExecutingAssembly(); var resourceName = $"VsixTesting.Invoker{(hive.Version.Major >= 17 ? ".17" : string.Empty)}.vsix"; using (var invoker = new TempFile(EmbeddedResourceUtil.ExtractResource(invokerAssembly, resourceName))) { EmbeddedResourceUtil.ApplyDateTime(invoker.Path, invokerAssembly, resourceName); if (installInvoker) { extensionsToInstall = extensionsToInstall.Concat(new[] { invoker.Path }); } var installResult = await VisualStudioUtil.InstallExtensionsAsync(hive, extensionsToInstall); output.WriteLine(installResult.Output); if (installResult.InstallCount > 0) { output.WriteLine("Clearing cache"); await VisualStudioUtil.ClearCacheAsync(hive); output.WriteLine("Updating configuration"); await VisualStudioUtil.UpdateConfigurationAsync(hive); } } if (resetSettings) { output.WriteLine("Resetting settings"); await VisualStudioUtil.ResetSettingsAsync(hive); } }); }