Пример #1
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();
        }