예제 #1
0
            public void SetUp()
            {
                terminatedSuccessfully = new ManualResetEvent(false);

                processTask = Tasks.StartProcessTask(Path.Combine(Environment.SystemDirectory, "cmd.exe"),
                    "/C exit " + COR_E_STACKOVERFLOW, Environment.CurrentDirectory);
                processTask.Terminated += processTask_Terminated;
                processTask.Start();
                Assert.IsTrue(processTask.Join(TimeSpan.FromSeconds(10)), "Wait for exit");
            }
예제 #2
0
        private void StartProcess(string hostConnectionArguments)
        {
            bool useElevation = HostSetup.Elevated && !DotNetRuntimeSupport.IsUsingMono;

            CreateTemporaryConfigurationFile();

            StringBuilder hostArguments = new StringBuilder();
            hostArguments.Append(hostConnectionArguments);

            if (HostSetup.DebuggerSetup == null)
                hostArguments.Append(@" /timeout:").Append((int)WatchdogTimeout.TotalSeconds);

            hostArguments.Append(@" /owner-process:").Append(Process.GetCurrentProcess().Id);

            if (HostSetup.ApplicationBaseDirectory != null)
                hostArguments.Append(@" /application-base-directory:""").Append(
                    FileUtils.StripTrailingBackslash(HostSetup.ApplicationBaseDirectory)).Append('"');
            
            foreach (string hintDirectory in HostSetup.HintDirectories)
                hostArguments.Append(@" /hint-directory:""").Append(
                    FileUtils.StripTrailingBackslash(hintDirectory)).Append('"');

            hostArguments.Append(@" /configuration-file:""").Append(temporaryConfigurationFilePath).Append('"');

            if (HostSetup.ShadowCopy)
                hostArguments.Append(@" /shadow-copy");

            if (HostSetup.DebuggerSetup != null)
                hostArguments.Append(@" /debug");

            hostArguments.Append(" /severity-prefix");

            if (useElevation)
                hostArguments.Append(" /quiet");

            severityPrefixParser = new SeverityPrefixParser();

            processTask = CreateProcessTask(GetInstalledHostProcessPath(), hostArguments.ToString(), HostSetup.WorkingDirectory ?? Environment.CurrentDirectory);
            processTask.Terminated += HandleProcessExit;

            if (useElevation)
            {
                if (HostSetup.RuntimeVersion != null)
                    throw new HostException("The host does not support a non-default RuntimeVersion with Elevation.");

                processTask.UseShellExecute = true;
                processTask.ConfigureProcessStartInfo += (sender, e) =>
                {
                    e.ProcessStartInfo.Verb = "runas";
                    e.ProcessStartInfo.ErrorDialog = true;
                    e.ProcessStartInfo.ErrorDialogParentHandle = GetOwnerWindowHandle();
                };
            }
            else
            {
                processTask.CaptureConsoleOutput = true;
                processTask.CaptureConsoleError = true;
                processTask.ConsoleOutputDataReceived += LogConsoleOutput;
                processTask.ConsoleErrorDataReceived += LogConsoleError;

                // Force CLR runtime version.
                string runtimeVersion = HostSetup.RuntimeVersion;
                if (runtimeVersion == null)
                    runtimeVersion = DotNetRuntimeSupport.MostRecentInstalledDotNetRuntimeVersion;

                if (!runtimeVersion.StartsWith("v"))
                    runtimeVersion = "v" + runtimeVersion; // just in case, this is a common user error

                // http://msdn.microsoft.com/en-us/library/w4atty68.aspx
                if (runtimeVersion == "v4.0")
                    runtimeVersion = "v4.0.30319";

                processTask.SetEnvironmentVariable("COMPLUS_Version", runtimeVersion);
            }

            processTask.Start();
        }
예제 #3
0
        /// <inheritdoc />
        public IVisualStudio LaunchVisualStudio(VisualStudioVersion version, ILogger logger)
        {
            if (logger == null)
                throw new ArgumentNullException("logger");

            Pair<string, VisualStudioVersion>? installDirAndVersion = GetVisualStudioInstallDirAndVersion(version);
            if (!installDirAndVersion.HasValue)
            {
                logger.Log(LogSeverity.Debug, string.Format("Could not find Visual Studio version '{0}'.", version));
                return null;
            }

            string devenvPath = Path.Combine(installDirAndVersion.Value.First, "devenv.exe");
            ProcessTask devenvProcessTask = new ProcessTask(devenvPath, "", Environment.CurrentDirectory);

            logger.Log(LogSeverity.Debug, string.Format("Launching Visual Studio using path: '{0}'.", devenvProcessTask.ExecutablePath));
            devenvProcessTask.Start();

            System.Diagnostics.Process devenvProcess = devenvProcessTask.Process;
            if (devenvProcess != null)
            {
                int processId = devenvProcess.Id;

                Stopwatch stopwatch = Stopwatch.StartNew();
                for (;;)
                {
                    IVisualStudio visualStudio = GetVisualStudioFromProcess(processId, installDirAndVersion.Value.Second, true, logger);
                    if (visualStudio != null)
                        return visualStudio;

                    if (stopwatch.ElapsedMilliseconds > VisualStudioAttachTimeoutMilliseconds)
                    {
                        logger.Log(LogSeverity.Debug, string.Format("Stopped waiting for Visual Studio to launch after {0} milliseconds.", VisualStudioAttachTimeoutMilliseconds));
                        break;
                    }

                    if (!devenvProcessTask.IsRunning)
                        break;

                    Thread.Sleep(500);
                }
            }

            if (devenvProcessTask.IsTerminated && devenvProcessTask.Result != null)
            {
                if (! devenvProcessTask.Result.HasValue)
                    logger.Log(LogSeverity.Debug, "Failed to launch Visual Studio.", devenvProcessTask.Result.Exception);
            }

            return null;
        }