setr setr - 4 months ago 53
C# Question

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 ?

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



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\ sharedvcxitems\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