How can I programmatically retrieve a loaded project in Visual Studio 2008?
I want to create an hour counter to monitor my development time on a project. I want the time to increase whenever a certain project is active in Visual Studio 2008.
Can I progammatically find out which *.cs开发者_运维问答proj file is currently active in VS2008?
You can get the loaded solution via the DTE.Solution
property, and the active document via DTE.ActiveDocument
. There isn't really an "active project" because you never really activate projects, you only open solutions (which can contain multiple projects) and files (which happen to be in projects).
I suspect for a time-tracking requirement, getting the current solution would probably suffice. However, if you need to specifically distinguish between projects in the solution, you can do this using DTE.ActiveDocument.ProjectItem.ContainingProject
.
精彩评论