以编程方式创建 Visual Studio 项目

发布于 2024-12-25 21:01:56 字数 1774 浏览 1 评论 0原文

正如我的问题所说,我想基于模板创建一个新项目,该模板已经创建了测试并且工作正常,但是当我尝试在 C# 代码中(在 mvc3 项目中)执行此操作时遇到两个问题。

  1. EnvDTE80、EnvDTE90 和 EnvDTE100 之间有哪些区别,因为我尝试执行 此示例EnvDTE100 但它不起作用,因为对象句柄是 Solution4 而不是 Solution2 并且 Solution4 没有相同的行为。
  2. 如何在不使用默认路径但需要一个特定文件夹的情况下创建项目

UPDATE

如果我使用名为 EnvDTE80 的 dll,则这里的代码可以工作

  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 的命名空间中

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冬天旳寂寞 2025-01-01 21:01:56

EnvDTE80、EnvDTE90 和 EnvDTE100 分别是 VS 8.0 (2005)、9.0 (2008) 和 10.0 (2010) 的 DTE 类型库。

截至 VS2010,只有两个 DTE 根对象接口 - DTE2 是最新的。因此,要获取 VS 2010 的 DTE 对象,您需要执行以下操作:

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

请注意,ProgID 代表“10.0”,但变量类型仍然是 EnvDTE80.DTE2

其余的应该从那里开始工作。另请注意,如果需要,您可以随时将 Solution4 转换为 Solution2(但 GetProjectTemplate 应直接在 Solution4 上使用) >)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文