Exemple #1
0
        /// <summary>
        /// Start experimental instance of Visual Studio. This will be killed on cleanup, except if a debugger is attached (in which case it can reuse the existing instance).
        /// </summary>
        private static (DTE, Process, bool) InitDTE()
        {
            bool    killVisualStudioProcessDuringTearDown;
            var     visualStudioPath = VSLocator.VisualStudioPath;
            Process process;

            // First, we try to check if an existing instance was launched
            var searcher            = new ManagementObjectSearcher($"select CommandLine,ProcessId from Win32_Process where ExecutablePath='{visualStudioPath.Replace(@"\", @"\\")}' and CommandLine like '% /RootSuffix Exp'");
            var retObjectCollection = searcher.Get();
            var result = retObjectCollection.Cast <ManagementObject>().FirstOrDefault();

            if (result != null)
            {
                var processId = (uint)result["ProcessId"];
                process = Process.GetProcessById((int)processId);
                killVisualStudioProcessDuringTearDown = false;
            }
            else
            {
                var psi = new ProcessStartInfo
                {
                    FileName         = visualStudioPath,
                    WorkingDirectory = Path.GetDirectoryName(visualStudioPath),
                    Arguments        = StartArguments,
                    UseShellExecute  = false,
                };

                // Override Xenko dir with path relative to test directory
                psi.EnvironmentVariables["XenkoDir"] = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"..\..\..\..");

                process = Process.Start(psi);
                if (process == null)
                {
                    throw new InvalidOperationException("Could not start Visual Studio instance");
                }

                // Since we are the one starting it, let's close it when we are done
                // (except if a debugger is attached, we assume developer want to iterate several time on it and will exit Visual Studio himself)
                killVisualStudioProcessDuringTearDown = !Debugger.IsAttached;
            }

            // Wait for 60 sec
            for (int i = 0; i < 60; ++i)
            {
                if (process.HasExited)
                {
                    throw new InvalidOperationException($"Visual Studio process {process.Id} exited before we could connect to it");
                }

                var matchingDte = VisualStudioDTE.GetDTEByProcess(process.Id);
                if (matchingDte != null)
                {
                    return(matchingDte, process, killVisualStudioProcessDuringTearDown);
                }

                Thread.Sleep(1000);
            }

            throw new InvalidOperationException($"Could not find the Visual Studio DTE for process {process.Id}, or it didn't start in time");
        }
Exemple #2
0
        public static void WriteError(string message, string fileName, int lineNumber = 0,
                                      int columnNumber   = 0,
                                      string helpKeyword = null, TaskCategory taskCategory = TaskCategory.User,
                                      string projectFile = null,
                                      bool allowOpenFile = false,
                                      bool activatePane  = true)
        {
            SimpleVsHierarchy hierarchyItem = projectFile != null ? new SimpleVsHierarchy(projectFile) : null;
            ErrorTask         task          = new ErrorTask
            {
                HierarchyItem = hierarchyItem,
                Category      = taskCategory,
                Document      = fileName,
                Line          = lineNumber,
                ErrorCategory = TaskErrorCategory.Error,
                Text          = message,
                Column        = columnNumber,
                HelpKeyword   = helpKeyword
            };

            if (allowOpenFile)
            {
                task.Navigate += (sender, args) => VisualStudioDTE.TryOpenFile(fileName, lineNumber, hierarchyItem);
            }

            AddTask(task, activatePane);
        }
Exemple #3
0
 private KeyValuePair <TestRun, List <MsTestError> > OpenTestResultFileAndGetResults(Project project, string fileName)
 {
     if (File.Exists(fileName))
     {
         VisualStudioDTE.TryOpenFile(fileName);
         var run = TestRun.LoadFromFile(fileName);
         List <MsTestError> failedTests = MsTestError.FromTestRun(run).ToList();
         foreach (var error in failedTests)
         {
             Output.WriteError($"{error.TestName}={error.ErrorMessage}", error.TestPath, error.Line, 0, null, TaskCategory.User, project.FullPath, File.Exists(error.TestPath), false);
         }
         SetTestRunOnResultsWindowToIndex(1);                 // Alle läufe in einem ergebis fenster zeigen
         return(new KeyValuePair <TestRun, List <MsTestError> >(run, failedTests));
     }
     return(new KeyValuePair <TestRun, List <MsTestError> >(null, new List <MsTestError>()));
 }
        private void Control_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var lb = (sender) as ListBox;

            if (lb != null)
            {
                var task = lb.SelectedItem as ErrorTask;
                if (task != null)
                {
                    VisualStudioDTE.TryOpenFile(task.Document, task.Line, task.HierarchyItem as SimpleVsHierarchy);
                }

                //	var invoker = ReflectionHelper.GetEventInvoker(task, "Navigate");
                //	if (invoker != null)
                //	{
                //		invoker.Invoke(task, new object[] { task, null });
                //	}
            }
        }
 public static T Get <T>(this IServiceProvider serviceProvider)
 {
     if (typeof(T) == typeof(ITrackSelection))
     {
         return((T)(trackSelection ?? (trackSelection = VisualStudioDTE.GetITrackSelection(VisualStudioIds.TeamExplorerToolWindowId.ToGuid()))));
     }
     if (serviceProvider != null)
     {
         if (vsServiceMapping.ContainsKey(typeof(T)))
         {
             return((T)serviceProvider.GetService(vsServiceMapping[typeof(T)]));
         }
         if (typeof(T) == typeof(VersionControlExt))
         {
             return((T)Get <DTE2>(serviceProvider).GetObject("Microsoft.VisualStudio.TeamFoundation.VersionControl.VersionControlExt"));
         }
         return((T)serviceProvider.GetService(typeof(T)));
     }
     return(default(T));
 }
        private static async Task <Process> GetDebuggerProcess(EditorViewModel editor)
        {
            // Check if the current solution is opened in some IDE instance
            var process = await VisualStudioService.GetVisualStudio(editor.Session, false);

            if (process == null)
            {
                // If not, let the user pick an instance
                var picker = new DebuggerPickerWindow(VisualStudioDTE.GetActiveInstances());

                var result = await picker.ShowModal();

                if (result == DialogResult.Ok)
                {
                    process = await picker.SelectedDebugger.Launch(editor.Session);
                }
            }

            return(process);
        }