/// <summary> /// Create a Visual Studio process. /// </summary> /// <param name="info">Startup information.</param> private void StartNewInstance(VsIdeStartupInfo startupInfo) { try { Debug.Assert(startupInfo != null); Debug.Assert(m_process == null, "VisualStudioIde.StartNewInstance: m_process should be null!"); Process process = new Process(); process.StartInfo.UseShellExecute = false; if (startupInfo.WorkingDirectory != null) { process.StartInfo.WorkingDirectory = startupInfo.WorkingDirectory; } process.StartInfo.FileName = VsRegistry.GetVsLocation(startupInfo.RegistryHive); Debug.Assert(!string.IsNullOrEmpty(process.StartInfo.FileName)); // Note that this needs to be partial (not $-terminated) as we partially match/replace. Regex versionRegex = new Regex(@"^[0-9]+\.[0-9]+"); string hiveVersion = versionRegex.Match(startupInfo.RegistryHive).Value; string hiveSuffix = versionRegex.Replace(startupInfo.RegistryHive, string.Empty); if (!string.IsNullOrEmpty(hiveSuffix)) { process.StartInfo.Arguments = "/RootSuffix " + hiveSuffix; } process.Exited += new EventHandler(ProcessExited); process.EnableRaisingEvents = true; if (!process.Start()) { throw new VsIdeTestHostException(Resources.FailedToStartVSProcess); } m_process = process; string progId = string.Format(CultureInfo.InvariantCulture, "{0}.{1}", VisualStudioIde.BaseProgId, hiveVersion); m_dte = GetDteFromRot(progId, m_process.Id); if (m_dte == null) { throw new VsIdeTestHostException(Resources.FailedToGetDte); } } catch (Exception ex) { Debug.Fail("VsIde.StartNewInstance: " + ex.ToString()); throw; } }
/// <summary> /// Constructor. Starts new instance of VS IDE. /// </summary> public VisualStudioIde(VsIdeStartupInfo info) { Debug.Assert(info != null); if (string.IsNullOrEmpty(info.RegistryHive)) { info.RegistryHive = VsRegistry.GetDefaultVersion(); if (string.IsNullOrEmpty(info.RegistryHive)) { // Please no Debug.Assert. This is a valid case. throw new VsIdeTestHostException(string.Format(CultureInfo.InvariantCulture, Resources.CannotFindVSInstallation, info.RegistryHive)); } } StartNewInstance(info); }