Exemplo n.º 1
0
        public bool TrySetDebuggerOptions(string projectName, string excelExePath, string excelAddInToDebug)
        {
            try
            {
                MessageFilter.Register();

                var project = _dte.GetProjectByName(projectName);
                if (project != null)
                {
                    _log.Debug($"Found project: {project.Name}");
                    var configuration = project
                                        .ConfigurationManager
                                        .ActiveConfiguration;

                    var startAction    = configuration.Properties.Item("StartAction");
                    var startProgram   = configuration.Properties.Item("StartProgram");
                    var startArguments = configuration.Properties.Item("StartArguments");

                    startAction.Value    = 1; // Start external program
                    startProgram.Value   = excelExePath;
                    startArguments.Value = $@"""{Path.GetFileName(excelAddInToDebug)}""";

                    project.Save(string.Empty);

                    return(true);
                }

                return(false);
            }
            finally
            {
                MessageFilter.Revoke();
            }
        }
Exemplo n.º 2
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);
        }