Create a Visual Studio project programmatically

前端 未结 1 1284
自闭症患者
自闭症患者 2020-12-14 11:31

As my question say I want to create a new project based in a template which already created an tested and works fine, but i have two problems when i tried to do it in C# cod

相关标签:
1条回答
  • 2020-12-14 12:22

    EnvDTE80, EnvDTE90 and EnvDTE100 are DTE type libraries for VS 8.0 (2005), 9.0 (2008) and 10.0 (2010), correspondingly.

    There are only two DTE root object interfaces, as of VS2010 - DTE2 being the latest. So, to get the DTE object for VS 2010, you do:

    System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
    Object obj = System.Activator.CreateInstance(type, true);
    EnvDTE80.DTE2 dte = (EnvDTE100.DTE2)obj;
    

    Note that ProgID is for "10.0", but variable type is still EnvDTE80.DTE2.

    The rest should work from there. Note also that you can always cast Solution4 to Solution2 if you need it (but GetProjectTemplate should be available directly on Solution4).

    0 讨论(0)
提交回复
热议问题