使用EnvDTE.DTE创建Visual Studio 2015的空C++项目

3

我正在尝试使用EnvDTE以编程方式创建Visual C++空项目。但是,组成的项目文件夹中不包括vcxproj和vcxproj.filter文件。由于当我在Visual Studio中打开该解决方案时,文件结构被破坏了。如何通过EnvDTE创建正确的空C++项目?在哪里可以找到C++空项目模板?

InitializeComponent();
System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.14.0");
Object obj = System.Activator.CreateInstance(type, true);
EnvDTE.DTE dte = (EnvDTE.DTE)obj;
dte.MainWindow.Visible = true; // optional if you want to See VS doing its thing

// create a new solution
dte.Solution.Create(@"C:\NewSolution\", "NewSolution");
var solution = dte.Solution;

 EnvDTE.Project project = solution.AddFromTemplate(@"C:\Program Files (x86)
 \Microsoft Visual Studio 14.0\Common7\IDE\ProjectTemplates\VC\General\
 sharedvcxitems\shared.vstemplate", @"C:\NewSolution\TestApp", "TestApp");

// save and quit
dte.ExecuteCommand("File.SaveAll");

dte.Quit();
1个回答

2

通常我有一个名为.vcxproj的模板文件在私人文件夹中,像你这样的程序,所以不使用标准模板。

此外,标准VC模板文件夹可能会更改,因此必须通过代码解析位置(除非您只是针对自己或已知机器进行编码)。

在您的示例中,您的模板路径无效

C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ ProjectTemplates \ VC \ General \ s haredvcxitems \ shared.vstemplate

应该是:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\ProjectTemplates\VC\General\sharedvcxitems\shared.vstemplate

编辑: 通过打开或创建项目,然后单击菜单 文件>导出模板 来创建自己的模板。


感谢您的帮助和建议。但是,如果我打开VS 2015并创建空的C++项目,则会创建vcxproj文件,但是使用此模板不会创建。我在哪里可以找到一个创建带有.vcxproj的空C++项目的模板? - Yunus
1
创建任何C++项目,然后单击“文件>导出模板”。这将创建一个包含模板文件的zip文件。 - Visual Micro

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接