11

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# code (in a mvc3 project).

  1. Which are the differences between EnvDTE80, EnvDTE90 and EnvDTE100 because i tried to do this example with EnvDTE100 but it doesn't work because the object handle it's Solution4 not Solution2 and Solution4 doesn't have the same behavior.
  2. How can I create the project without use the default path, but an specific folder that i need

UPDATE

here's the code that works if I used the dll called EnvDTE80

  System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.8.0");
  Object obj = System.Activator.CreateInstance(type, true);
  EnvDTE80.DTE2 dte = (EnvDTE80.DTE2)obj;
  Solution2 _solution = (Solution2)dte.Solution;
  string projectTemplatePath = @"C:\Documents and Settings\jmachado\Escritorio";
  projectTemplatePath =_solution.GetProjectTemplate("",""); <-- looking for some overload to create project based in a specific folder an not from '<drive>:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ProjectTemplates\Language.'

But if i used the EnvDTE100

  System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
  Object obj = System.Activator.CreateInstance(type, true);
  EnvDTE100.DTE2 dte = (EnvDTE100.DTE2)obj;
  Solution4 _solution = (Solution4)dte.Solution;
  string projectTemplatePath = @"C:\Documents and Settings\jmachado\Escritorio";
  projectTemplatePath =_solution.GetProjectTemplate("",""); <-- looking for some overload to create project based in a specific folder an not from '<drive>:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ProjectTemplates\Language.'

and Say's that DTE2 doesn't exit's in the namespace of EnvDTE100

John Saunders
  • 160,644
  • 26
  • 247
  • 397
Jorge
  • 17,896
  • 19
  • 80
  • 126
  • It sounds like you want to get involved with a virtual directory, rather than copying all your code in to each new project you can use one source, so you can make all bug fixes at once (rather than having to fix for all projects). http://learn.iis.net/page.aspx/150/understanding-sites-applications-and-virtual-directories-on-iis/ – Lloyd Powell Jan 09 '12 at 15:13
  • 1
    Could you share some example code of what you're actually trying to achieve to clarify your question? – Joachim Isaksson Jan 09 '12 at 15:13
  • @Joachim Isaksson sure, give two minutes to update the question – Jorge Jan 09 '12 at 15:14
  • @Joachim Isaksson done, the question it's already update – Jorge Jan 09 '12 at 15:21
  • See http://stackoverflow.com/questions/6833119/create-a-solution-and-add-a-project-using-visualstudio-dte-10-0 which seems to deal with what you're seeing. – Joachim Isaksson Jan 09 '12 at 15:24
  • The differences between `EnvDTExxx` is that the `xxx` is the 'version' of the IDE the object represents. i think 80 is 2005, 90 is 2008 and 100 is 2010. – George Duckett Jan 09 '12 at 15:37
  • @Joachim Isaksson Ok, the solution of work's to the first doubt but to the second one – Jorge Jan 09 '12 at 15:40
  • Here is a similar post: http://stackoverflow.com/questions/770264/visual-studio-extensibility-programmatically-creating-a-project/18156838#18156838 Hope it helps! – cvillalobosm Aug 12 '13 at 15:06

1 Answers1

7

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

Brain2000
  • 4,655
  • 2
  • 27
  • 35
Pavel Minaev
  • 99,783
  • 25
  • 219
  • 289
  • Hi and thanks for asking, now still remaining my second problem, how can I created the project with a specific path different that visual studio has be default?? – Jorge Jan 12 '12 at 02:26
  • I don't quite understand the request. If you have a custom project template of your own that you did not copy to VS template folder, then don't use `GetProjectTemplate`, but just pass the full path to your template directly to `AddFromTemplate`. – Pavel Minaev Jan 12 '12 at 23:13
  • is there a VS2015 equivalent, or do we just use DTE100? – tofutim Aug 12 '16 at 22:42
  • You need to use the appropriate DTE version in `GetTypeFromProgID`, e.g. `VisualStudio.DTE.14.0` for VS 2015. When there are several Visual Studio versions installed side by side, this will determine which one you're talking to. The interface name (`DTE2`) stays the same, though. Those are cumulative - every new version supports all the old interfaces. Similarly, the type libraries containing definitions of those older interfaces are shipped with new VS versions. – Pavel Minaev Aug 12 '16 at 22:52
  • 1
    @Pavel Minaev... The code you show above does not work for VS2015, it errs saying DTE2 is not available on the EnvDTE100 object. And i am using the right string reference for VS2015 in the GetTypeFromProgId method. – dinotom Sep 05 '16 at 01:58