locked
(VCProject)EnvDTE.Project.Object doesn't work in 2010 RRS feed

Answers

  • Thanks for the feedback, Mats.

    You are right that two versions of assemblies should be maintained for VS 2008 and 2010. This is by design. You can submit the feedback in http://connect.microsoft.com site to let product group to consider it in the future releases. Thanks.


    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    See what's happening in MSDN forum? Follow us at Twitter.
    Wednesday, May 26, 2010 3:49 AM

All replies

  • Hi Mats,

    Thanks for reporting this issue.

    I tested the sample code in the link you referenced. It doesn't work because of some obsolete methods and types like ReferenceConfiguration. I will report it to content team. However, the VCProject type conversion works correctly in my box.

    In order to reproduce the issue in my environment, would you please provide following information?

    1. The code which can reproduce the error

    2. Which project template you used to create VC project

    Thanks.


    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    See what's happening in MSDN forum? Follow us at Twitter.
    Monday, May 24, 2010 2:03 AM
  • VS2010 does not like the 2008 version assemblies. The problem comes up when you are referencing the 9.0.0.0 version of Microsoft.VisualStudio.VCProjectEngine.

    After relinking my vspackage against the 10.0.0.0 versions of the mentioned assembly, the problem went away. In VS 2010, that is. Those versions don't work with VS 2008, so it appears I have to maintain and distribute two versions of my extension package.

    Surely, this compaibility-breach can't be intentional?

     

    To repro, just use VS2008, invoke the the wizard to create a c# Visual Studio Integration Package, check the Menu Command checkbox, add references to the 2008 versions of EnvDTE and Microsoft.VisualStudio.VCProjectEngine, and replace the contents of the MenuItemCallback with the following:

        private EnvDTE.DTE dte;
    
        private EnvDTE.Project get_startup_project()
        {
          dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE));
          if (dte == null)
            return null;
          if (dte.Solution == null)
            return null;
          if (dte.Solution.SolutionBuild == null)
            return null;
    
          EnvDTE.SolutionBuild sb = dte.Solution.SolutionBuild;
          if (sb.StartupProjects == null)
            return null;
          string projname = "";
          foreach (string s in (Array)sb.StartupProjects)
            projname += s;
          return dte.Solution.Item(projname);
        }
    
        private void MenuItemCallback(object sender, EventArgs e)
        {
          EnvDTE.Project p = get_startup_project();
          Microsoft.VisualStudio.VCProjectEngine.VCProject vcp =
            (Microsoft.VisualStudio.VCProjectEngine.VCProject) p.Object;
          Trace.WriteLine(vcp.Name);
        }
    

    Debug the project, which starts a 9.0Exp VS2008. Load a c++ project and invoke the command. This works.

    Now replace the VCProjectEngine assembly reference with the one from 2010, and (still in VS2008) try the scenario again. This gives:

    "Unable to cast COM object of type 'System.__ComObject' to interface type 'Microsoft.VisualStudio.VCProjectEngin.VCProject'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{885C172E-5B7A-43B9-8AD0-697F48233772}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE))."

    Now, redo these two experiments from VS2010. When referencing the 10.0.0.0 version of VCProjectEngine, it works. When referencing the 9.0.0.0 version it fails with the error message of the original post.

     

    Hence, it appears that I must provide two versions of my package, which is highly inconvenient and ugly.

     

    /Mats

    • Proposed as answer by Alexis Pautrot Friday, September 14, 2012 3:47 PM
    • Unproposed as answer by Alexis Pautrot Friday, September 14, 2012 3:47 PM
    Monday, May 24, 2010 6:31 AM
  • Thanks for the feedback, Mats.

    You are right that two versions of assemblies should be maintained for VS 2008 and 2010. This is by design. You can submit the feedback in http://connect.microsoft.com site to let product group to consider it in the future releases. Thanks.


    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    See what's happening in MSDN forum? Follow us at Twitter.
    Wednesday, May 26, 2010 3:49 AM
  • I had the same problem. I adress the issue by isolating the code into a separate assembly, declined into two version, one for 2008, one for 2012. Same code, but two different projects, with different referenced assemblies. My addin is detecting the version of Visual Studio (http://stackoverflow.com/questions/11082436/detect-the-visual-studio-version-inside-a-vspackage) load the appropriate assembly and invoke the same methods from loaded assembly to deal with the project properties.

    Thus I have been able to provide the same addin that works for both versions of Visual Studio.

    Friday, September 14, 2012 3:55 PM