示例#1
0
        public EnvDTE.Project GetProjectByName(string projectName)
        {
            _log.Debug("Starting GetProjectByName");

            var vsProcessId = GetVisualStudioProcessId();

            _log.Debug($"VS Process ID: {vsProcessId}");

            var dte = GetDevToolsEnvironment(vsProcessId);

            _log.Debug($"DevToolsEnvironment?: {dte}");

            if (dte == null)
            {
                return(null);
            }

            if (!_isMessageFilterRegistered)
            {
                MessageFilter.Register();
                _isMessageFilterRegistered = true;
            }

            var project = dte
                          .Solution
                          .Projects
                          .OfType <EnvDTE.Project>()
                          .SelectMany(GetProjectAndSubProjects)
                          .SingleOrDefault(p =>
                                           string.Compare(p.Name, projectName, StringComparison.OrdinalIgnoreCase) == 0);

            if (project == null)
            {
                _log.Debug("Did not find project");
                _log.Debug($"Looked for {projectName}");
                _log.Debug("List of projects:");

                foreach (var p in dte.Solution.Projects)
                {
                    _log.Debug($"    {p.GetType().Name}  -  Is EnvDTE? {p is EnvDTE.Project}  -  {(p as EnvDTE.Project)?.Name}");
                }
            }
            return(project);
        }
示例#2
0
        // Class containing the IOleMessageFilter
        // thread error-handling functions.

        // Start the filter.
        public static void Register()
        {
            IOleMessageFilter newFilter = new MessageFilter();

            CoRegisterMessageFilter(newFilter, out _);
        }