1

我想为 VS 编写一个加载项,在解决方案中获取所选项目,并卸载所有依赖它的项目。是否可以?

我知道有可能使用宏来实现,但我想使用插件来实现。

4

1 回答 1

1

这是解决方案

    private const string UnloadProjectCommandName = "Project.UnloadProject";
    private const string ReloadProjectCommandName = "Project.ReloadProject";

    public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
    {
        handled = false;
        if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
        {
            if (commandName == "Build7.Connect.Build7")
            {
                handled = true;
                var solution = (((SolutionClass)(_applicationObject.Solution)));

                var solutionExplorer = _applicationObject.Windows.Item(Constants.vsWindowKindSolutionExplorer);
                solutionExplorer.Activate();

                var solutionHierarchy = (UIHierarchy)solutionExplorer.Object;
                string solutionName = solution.Properties.Item("Name").Value.ToString();

                var projects = solution.Projects;
                foreach (Project project in projects)
                {
                    var projPath = solutionName + "\\" + project.Name;
                    var obj = solutionHierarchy.GetItem(projPath);
                    obj.Select(vsUISelectionType.vsUISelectionTypeSelect);
                    _applicationObject.ExecuteCommand(UnloadProjectCommandName);

                }

                foreach (Project project in projects)
                {
                    var projPath = solutionName + "\\" + project.Name;
                    var obj = solutionHierarchy.GetItem(projPath);
                    obj.Select(vsUISelectionType.vsUISelectionTypeSelect);
                    _applicationObject.ExecuteCommand(ReloadProjectCommandName);

                }
            }
        }
    }

感谢杰里米詹姆森的帖子

于 2013-04-08T10:14:05.240 回答