在设计项目调试环境的时候,每次只能从Solution对象中获取当前激活的项目(可能是多个,当前选中的),操作如下
EnvDTE.DTE dteObject;
Array projs = (Array)dteObject.ActiveSolutionProjects;
通过这种方法来获取当前选中的项目列表。但是这个并不能达到我的目的,我希望的是获取当前启动的项目,也就是F5启动起来的那个项目,没有办法
这个方面的资料真的很少,于是登陆微软的官网MSDN,在里面搜索"EnvDTE 获取启动项目",终于让我如愿以偿了,呵呵
解决方案如下,需要从开发环境对象中获取解决方案,解决方案中再获取编译对象即可,如下代码是获取当前编译,调试项目的代码:
EnvDTE.Project GetStartupBuildProject(EnvDTE dteObject)
{
Solution sln = dteObject.Solution;
Array startsProjects = sln.SolutionBuild.StartupProjects as Array;
if(startsProjects == null || startsProjects.Length < 1)
return null;