How to: Add a Project Template to Visual Studio Solution programmatically using VSX

Type vsType = Type.GetTypeFromProgID("VisualStudio.DTE.10.0");
DTE dte = Activator.CreateInstance(vsType) as DTE;
Solution2 soln = (Solution2)dte.Solution;

string prjPath=@”C:\My Project”; // Project Path – where the new solution is created
string templatePath; // path of ConsoleApplication Template

templatePath = soln.GetProjectTemplate("", "vbproj");
soln.AddFromTemplate(templatePath, prjPath, "My Project", false);

To add a custom template ( template created from a project), we can directly specify the template location in AddFromTemplate method as follows –
soln.AddFromTemplate(@"C:\\CustomTemplate.vstemplate", csPrjPath, "Sample Windows Application", false);
Related Links:

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s