简体   繁体   中英

EnvDTE.DTE create empty C++ project for Visual Studio 2015

I am trying to create a Visual C++ Empty project programmatically with EnvDTE . But composed project folder does not include vcxproj and vcxproj.filter files. Due to the fact when I open that solution at Visual Studio, file structure is corrupted. How can I create proper Empty C++ project via EnvDTE? Where can I find C++ Empty Project template ?

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();

Normally I have a .vcxproj template in private folder with a program such as yours so don't use the standard templates.

Furthermore, the standard VC templates folder can change so the location must be resolved via code (unless you are just coding for your own or known machine).

In your example your template path is invalid

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

Should be:-

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

edit: Create your own template by opening or creating a project and then click menu File>Export Template

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM