Example #1
0
        /// <summary>
        /// Attaches Visual Studio (2012) to the specified process.
        /// </summary>
        /// <param name="process">The process.</param>
        public static void Attach(this System.Diagnostics.Process process)
        {
            // Reference visual studio core
            DTE dte = (DTE)Marshal.GetActiveObject(@"VisualStudio.DTE.11.0");

            // Register the IOleMessageFilter to handle any threading errors.
            MessageFilter.Register();

            // Try loop - visual studio may not respond the first time.
            int tryCount = 50;

            while (tryCount-- > 0)
            {
                try {
                    EnvDTE.Processes processes  = dte.Debugger.LocalProcesses;
                    Process          DTEprocess = processes.Cast <Process>().Where(
                        proc => proc.ProcessID == process.Id).First();
                    DTEprocess.Attach();
                    break;
                }
                catch (COMException) {
                    System.Threading.Thread.Sleep(500);
                }
            }
            // and turn off the IOleMessageFilter.
            MessageFilter.Revoke();
        }
Example #2
0
        private static void Main(string[] args)
        {
            _path       = args[0];
            _appName    = args[1];
            _executable = args[2];

            _process = StartProcess();
            AttachProcess();

            Console.WriteLine("Press <ENTER> to exit Debugger");
            Console.ReadKey();
            _process.Kill();
        }
            public ExecutionContext(IOutputWindowPane pane, Dispatcher dispatcher, System.Diagnostics.Process process, bool debug, DTE2 dte, IIdeTracer tracer, Version specRunVersion)
            {
                this.pane           = pane;
                this.dispatcher     = dispatcher;
                this.process        = process;
                this.debug          = debug;
                this.dte            = dte;
                this.tracer         = tracer;
                this.specRunVersion = specRunVersion;

                if (specRunVersion >= SpecRun12)
                {
                    shouldAttachToMain = null;
                }

                process.OutputDataReceived += OnMessageReceived;
                process.ErrorDataReceived  += OnMessageReceived;
            }
Example #4
0
        private void RunProcess(string exePath, string arguments)
        {
            WriteToOutputWindow("Starting build...");
            WriteToOutputWindow(exePath + " " + arguments);
            WriteToOutputWindow(string.Empty);

            using (System.Diagnostics.Process proc = new System.Diagnostics.Process())
            {
                proc.StartInfo.FileName               = exePath;
                proc.StartInfo.Arguments              = arguments;
                proc.StartInfo.UseShellExecute        = false;
                proc.StartInfo.CreateNoWindow         = true;
                proc.StartInfo.RedirectStandardOutput = true;

                proc.OutputDataReceived += new System.Diagnostics.DataReceivedEventHandler(proc_OutputDataReceived);
                proc.Start();

                proc.BeginOutputReadLine();
                proc.WaitForExit();
            }
        }
        public void ExecuteTests(string consolePath, string commandArgs, bool debug, Version specRunVersion)
        {
            string command = string.Format("{0} {1}", consolePath, commandArgs);

            tracer.Trace(command, GetType().Name);

            var pane          = outputWindowService.TryGetPane(OutputWindowDefinitions.SpecRunOutputWindowName);
            var displayResult = pane != null;
            var dispatcher    = Dispatcher.CurrentDispatcher;

            var process = new System.Diagnostics.Process
            {
                StartInfo =
                {
                    FileName               = consolePath,
                    Arguments              = commandArgs,
                    UseShellExecute        = false,
                    RedirectStandardOutput = true,
                    RedirectStandardError  = true,
                    CreateNoWindow         = true
                }
            };

            var executionContext = new ExecutionContext(displayResult ? pane : null, dispatcher, process, debug, dte, tracer, specRunVersion);

            if (displayResult)
            {
                pane.Clear();
                pane.Activate();
                dte.ToolWindows.OutputWindow.Parent.Activate();
                pane.WriteLine(command);
            }

            executionContext.Start();

            // async execution: we do not call 'process.WaitForExit();'
        }
        private void UseNHQG(Assembly assembly)
        {
            System.Diagnostics.Process nhqg = new System.Diagnostics.Process();
            ProcessStartInfo startInfo = new ProcessStartInfo();

            DirectoryInfo info = new DirectoryInfo(System.Environment.GetEnvironmentVariable("TEMP"));
            string tempFileFolderName = Guid.NewGuid().ToString("N");
            DirectoryInfo tempFileFolder = null;

            try
            {
                tempFileFolder = info.CreateSubdirectory(tempFileFolderName);

                startInfo.FileName = _model.NHQGExecutable;
                startInfo.WorkingDirectory = Path.GetDirectoryName(_model.NHQGExecutable);
                string[] args = new string[4];
                args[0] = "/lang:" + (_language == CodeLanguage.CSharp ? "CS": "VB");
                args[1] = "/files:\"" + assembly.Location + "\"";
                args[2] = "/out:\"" + tempFileFolder.FullName + "\"";
                args[3] = "/ns:" + _namespace;
                startInfo.Arguments = string.Join(" ", args);
                startInfo.WindowStyle = ProcessWindowStyle.Hidden;
                startInfo.ErrorDialog = false;
                startInfo.CreateNoWindow = true;
                startInfo.RedirectStandardOutput = true;
                startInfo.UseShellExecute = false;
                nhqg.StartInfo = startInfo;

                Log("Running NHQG with parameters: " + String.Join(" ", args));

                nhqg.Start();
                StreamReader output = nhqg.StandardOutput;
                nhqg.WaitForExit(); // Timeout?

                if (nhqg.ExitCode != 0)
                {
                    throw new TargetException("NHQG exited with code " + nhqg.ExitCode.ToString());
                }
                else
                {
                    string consoleOut = output.ReadToEnd();
                    if (!string.IsNullOrEmpty(consoleOut) && consoleOut.StartsWith("An error occured:"))
                    {
                        throw new TargetException("NHQG exited with the following error:\n\n" + consoleOut);
                    }
                    else
                    {
                        foreach (FileInfo file in tempFileFolder.GetFiles())
                        {
                            string filePath = Path.Combine(_modelFilePath, file.Name);
                            file.CopyTo(filePath , true);
                            AddToProject(filePath, prjBuildAction.prjBuildActionCompile);
                        }
                    }
                }
            }
            finally
            {
                if (tempFileFolder != null)
                    tempFileFolder.Delete(true);
            }
        }
        public void ExecuteTests(string consolePath, string commandArgs, bool debug, Version specRunVersion)
        {
            string command = string.Format("{0} {1}", consolePath, commandArgs);
            tracer.Trace(command, GetType().Name);

            var pane = outputWindowService.TryGetPane(OutputWindowDefinitions.SpecRunOutputWindowName);
            var displayResult = pane != null;
            var dispatcher = Dispatcher.CurrentDispatcher;

            var process = new System.Diagnostics.Process
                {
                    StartInfo =
                        {
                            FileName = consolePath,
                            Arguments = commandArgs,
                            UseShellExecute = false,
                            RedirectStandardOutput = true,
                            RedirectStandardError = true,
                            CreateNoWindow = true
                        }
                };

            var executionContext = new ExecutionContext(displayResult ? pane : null, dispatcher, process, debug, dte, tracer, specRunVersion);

            if (displayResult)
            {
                pane.Clear();
                pane.Activate();
                dte.ToolWindows.OutputWindow.Parent.Activate();
                pane.WriteLine(command);
            }

            executionContext.Start();

            // async execution: we do not call 'process.WaitForExit();'
        }
            public ExecutionContext(IOutputWindowPane pane, Dispatcher dispatcher, System.Diagnostics.Process process, bool debug, DTE2 dte, IIdeTracer tracer, Version specRunVersion)
            {
                this.pane = pane;
                this.dispatcher = dispatcher;
                this.process = process;
                this.debug = debug;
                this.dte = dte;
                this.tracer = tracer;
                this.specRunVersion = specRunVersion;

                if (specRunVersion >= SpecRun12)
                    shouldAttachToMain = null;

                process.OutputDataReceived += OnMessageReceived;
                process.ErrorDataReceived += OnMessageReceived;
            }