none
DTE bananza.

    Question

  • 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 everything is fine except when I debug, I am getting the debugger DTE instead of the one for VS hosting my package. This basically makes any debugging impossible.

    If I do it like this:

    m_dte = GetService(typeof(DTE));

    Then I am getting something that looks like a DTE instance, but m_dte.ActiveSolutionProjects throws an exception 0x80004005 (E_FAIL).

    Is there a way to get a DTE and to be able to debug it? Or am I asking tooo much?

    Best Regards,

    --Victor

    Thursday, June 21, 2012 12:19 AM

Answers

  • 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.

    Ryan

    • Marked as answer by Victor Havin Thursday, June 21, 2012 1:55 AM
    Thursday, June 21, 2012 1:04 AM
    Moderator

All replies

  • 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.

    Ryan

    • Marked as answer by Victor Havin Thursday, June 21, 2012 1:55 AM
    Thursday, June 21, 2012 1:04 AM
    Moderator
  • Hi Ryan,

    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.

    Thanks again,

    --Victor

    Thursday, June 21, 2012 1:57 AM
  • 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.

    Ryan

    Thursday, June 21, 2012 4:59 AM
    Moderator
  • 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 vhavin@us.ibm.com

    Thank you,

    Victor

    Thursday, June 21, 2012 6:50 PM