创建一个Visual Studio项目编程 [英] Create a Visual Studio project programmatically

查看:145
本文介绍了创建一个Visual Studio项目编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我的问题说,我想创建基于在已经创建了一个测试,工作正常模板的新项目,但我有两个问题,当我试图做它在C#code(在MVC3项目) 。

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. 哪些之间的 EnvDTE80,EnvDTE90和EnvDTE100 的差异,因为我试图做的这个例子用 EnvDTE100 的>,但它不工作,因为对象处理它的 Solution4 不是 Solution2 Solution4 不具有相同的行为。

  2. 如何创建一个没有使用默认路径的项目,而是一个特定的文件夹,我需要

  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

更新

这里的code,如果我使用所谓的DLL的作品 EnvDTE80

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

但是,如果我使用了 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.'

和萨伊那DTE2不会退出在 EnvDTE100

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

推荐答案

EnvDTE80,EnvDTE90和EnvDTE100是VS 8.0(2005年),9.0 DTE类型库(2008年)和10.0(2010),相应地。

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

有只有两个DTE根对象接口,VS2010的 - DTE2是最新的。因此,要获得DTE对象为VS 2010,你做的:

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);
EnvDTE8.DTE2 dte = (EnvDTE100.DTE2)obj;

注意,进程id是10.0,但变量类型仍然是 EnvDTE8.DTE2

其余部分应该从那里工作。还要注意的是,你总是可以投 Solution4 Solution2 如果你需要它(但 GetProjectTemplate 应可直接在 Solution4 )。

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

这篇关于创建一个Visual Studio项目编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆