Thursday, June 21, 2012 12:19 AM
I am trying to implement a VS extension for wotking with active projects. For that purpose I have to access an instance of DTE.
If I do it like this:
m_dte = (DTE)Marshal.GetActiveObject("VisualStudio.DTE");
Then I am getting something that looks like a DTE instance, but m_dte.ActiveSolutionProjects throws an exception 0x80004005 (E_FAIL).
Thursday, June 21, 2012 1:04 AMModerator
GetActiveObject gets a random version of VS from the ROT, as you noticed, it is never (or VERY rarely) the right way to get an instance of DTE. See also here: http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/73253b23-30a5-443e-8a60-e78fa232ce47. There is a bug where ActiveSolutionProjects will return E_FAIL if the solution explorer has never been shown. There are likely other ways to do what you are trying to do that don't involve DTE (and thus sidestep this bug), but that is hard to tell without knowing what you are trying to do exactly.
- Marked As Answer by Victor Havin Thursday, June 21, 2012 1:55 AM
Thursday, June 21, 2012 1:57 AM
Thanks for the prompt response. Indeed, if I open a solution explorer and (this is important) select a project in it, I get the legit list of projects. Unfortunately I can't do it without DTE, as I am dealing with a legacy code implemented in native C++ that is going back all the way to VS2003. I made myself a managed package to use it as a workbench for pocking around the VS SDK. This is where I got into trouble. Anyway, now that I know what is going on, I think I will figure something out.
Thursday, June 21, 2012 4:59 AMModerator
DTE alternatives have existed far into the past. Some things are only exposed via DTE, but that is a small number of things. For instance to enumerate projects you can use IVsSolution::GetProjectEnum. Now if the problem is you have some old legacy code you can't change that is different, but nothing about writing code in C++ means you have to use DTE.
Thursday, June 21, 2012 6:50 PM
I didn't want to go into the details because I was afraid this would make a lot of people on this forum yawn. The current implementation is heavily wired into the DTE functionality. I have to extend it, but I do not have time for rewriting this code. May be I will do it in the future. Using a managed package in place of the current one would certainly simplify a lot of things. For now I just created a managed workbench to prototype the extensions I am working on. I would like to keep the changes in the current project to the absolute necessary minimum because I know from the experience that anything you touch there tends to explode leaving you with a smoldering mess that takes days to repair. As I said, I wouldn't like to go into the details, since they are out of scope of this forum. If you wish, we can take this thread offline. You can contact me directly at firstname.lastname@example.org