【问题标题】:EnvDTE.DTE create empty C++ project for Visual Studio 2015EnvDTE.DTE 为 Visual Studio 2015 创建空的 C++ 项目
【发布时间】:2016-10-15 13:47:20
【问题描述】:

我正在尝试使用 EnvDTE 以编程方式创建一个 Visual C++ Empty 项目。但组合项目文件夹不包含 vcxproj 和 vcxproj.filter 文件。由于我在 Visual Studio 中打开该解决方案时,文件结构已损坏。如何通过 EnvDTE 创建正确的 Empty 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();

【问题讨论】:

    标签: c# c++ visual-studio visual-studio-2015 envdte


    【解决方案1】:

    通常我在私人文件夹中有一个.vcxproj 模板,其中包含您的程序,因此不要使用标准模板。

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

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

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

    应该是:-

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

    编辑:通过打开或创建项目来创建自己的模板,然后单击菜单File>Export Template

    【讨论】:

    • 感谢您的帮助和提示。但是如果我打开 VS 2015 并创建空的 c++ 项目,则会创建 vcxproj 文件,但使用此模板并没有创建它。在哪里可以找到使用 .vcxproj 创建空 c++ 项目的模板
    • 创建任何 C++ 项目,然后单击“文件>导出模板”。这将创建一个包含模板文件的 zip。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-03-29
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 2016-04-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多