예제 #1
0
        // Create a DevEnv process
        private void StartNewInstance(VsIdeStartupInfo info)
        {
            Debug.Assert(info != null);
            Debug.Assert(m_process == null, "VisualStudioIde.StartNewInstance: m_process should be 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(Resources.CannotFindVSInstallation(info.RegistryHive));
                }
            }

            Process process = new Process();

            process.StartInfo.UseShellExecute = false;
            if (info.WorkingDirectory != null)
            {
                process.StartInfo.WorkingDirectory = info.WorkingDirectory;
            }

            process.StartInfo.FileName = VSRegistry.GetVSLocation(info.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(info.RegistryHive).Value;
            string hiveSuffix  = versionRegex.Replace(info.RegistryHive, string.Empty);

            if (!string.IsNullOrEmpty(hiveSuffix))
            {
                process.StartInfo.Arguments = "/RootSuffix " + hiveSuffix;
            }

            if (!string.IsNullOrEmpty(info.AdditionalCommandLineArguments))
            {
                if (!string.IsNullOrEmpty(process.StartInfo.Arguments))
                {
                    process.StartInfo.Arguments += " ";
                }
                process.StartInfo.Arguments += info.AdditionalCommandLineArguments;
            }

            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);
            Debug.Assert(m_dte != null);
        }
예제 #2
0
        // Create a DevEnv process
        private void StartNewInstance(VsIdeStartupInfo info)
        {
            Debug.Assert(info != null);
            Debug.Assert(m_process == null, "VisualStudioIde.StartNewInstance: m_process should be 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(Resources.CannotFindVSInstallation(info.RegistryHive));
                }
            }

            Process process = new Process();
            process.StartInfo.UseShellExecute = false;
            if (info.WorkingDirectory != null)
            {
                process.StartInfo.WorkingDirectory = info.WorkingDirectory;
            }

            process.StartInfo.FileName = VSRegistry.GetVSLocation(info.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(info.RegistryHive).Value;
            string hiveSuffix = versionRegex.Replace(info.RegistryHive, string.Empty);

            if (!string.IsNullOrEmpty(hiveSuffix))
            {
                process.StartInfo.Arguments = "/RootSuffix " + hiveSuffix;
            }

            if (!string.IsNullOrEmpty(info.AdditionalCommandLineArguments))
            {
                if (!string.IsNullOrEmpty(process.StartInfo.Arguments))
                {
                    process.StartInfo.Arguments += " ";
                }
                process.StartInfo.Arguments += info.AdditionalCommandLineArguments;
            }

            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);
            Debug.Assert(m_dte != null);
        }
예제 #3
0
        /// <summary>
        /// Constructor. Starts new instance of VS IDE.
        /// </summary>
        public VisualStudioIde(VsIdeStartupInfo info)
        {
            Debug.Assert(info != null);

            StartNewInstance(info);
        }
예제 #4
0
        /// <summary>
        /// Constructor. Starts new instance of VS IDE.
        /// </summary>
        public VisualStudioIde(VsIdeStartupInfo info)
        {
            Debug.Assert(info != null);

            StartNewInstance(info);
        }