/// <summary> /// If run under debugger, attaches to the host session of test runner IDE. /// </summary> private void InitHostSession() { Debug.Assert(m_hostSession == null, "HA.InitHostSession: m_hostSession should be null!"); Debug.Assert(m_runConfig != null); if (m_runConfig.IsExecutedUnderDebugger) { // First check if there is Host Data in Run Config. // There is not host data when using HostType attribute (not using Run Config). string sessionId = null; VsIdeHostRunConfigData hostData = m_runConfig.HostData[Name] as VsIdeHostRunConfigData; if (hostData != null) { sessionId = hostData.SessionId; } else { try { // Try connecting by parent process id. // This is not very reliable because Windows does not really track parent-child process relationship. int ppid = ProcessUtil.GetParentProcessId(System.Diagnostics.Process.GetCurrentProcess().Id); sessionId = VsIdeHostSession.Prefix + ppid.ToString(CultureInfo.InvariantCulture); } catch (COMException ex) { m_runContext.ResultSink.AddResult(new TestRunTextResultMessage(Environment.MachineName, m_runContext.RunConfig.TestRun.Id, "Warning: " + ex.GetType() + ": " + ex.Message, TestMessageKind.TextMessage)); } } Debug.Assert(m_hostSession == null, "HA.InitHostSession: m_hostSession should be null!"); if (!string.IsNullOrEmpty(sessionId)) { // Now get the IDE runner session, the Uri is ipc://ServerPortName/AppName. string uri = string.Format( CultureInfo.InvariantCulture, "ipc://{0}/{1}", sessionId, VsIdeHostSession.RemoteObjectName); m_hostSession = (IVsIdeHostDebugger)Activator.GetObject(typeof(IVsIdeHostDebugger), uri); } else { m_runContext.ResultSink.AddResult(new TestRunTextResultMessage(Environment.MachineName, m_runContext.RunConfig.TestRun.Id, "Warning: failed to get session id for debugger VS IDE, debugging child VS will be disabled.", TestMessageKind.TextMessage)); } } }
private void CleanupHostSession() { // m_runConfig can be null if cleanup is called too early, i.e. before we completed init. if (m_runConfig != null && m_runConfig.IsExecutedUnderDebugger) { Debug.Assert(m_hostSession != null); try { m_hostSession.DetachDebugger(); // Detach from all attached. } finally { m_hostSession = null; } } }
private void CleanupHostSession() { // m_runConfig can be null if cleanup is called too early, i.e. before we comleted init. if (m_runConfig != null && m_runConfig.IsExecutedUnderDebugger) { Debug.Assert(m_hostSession != null); try { m_hostSession.DetachDebugger(); // Detach from all attached. } finally { m_hostSession = null; } } }