简体   繁体   中英

Create an empty database project programmatically using C#

I wanted to create an empty database project from Visual Studio 2017 programmatically. I tried creating a console application programmatically and was successful. Here is the code with which I tried creating a Console Application.

 Solution2 soln = (Solution2)dte.Solution;
 string dbTemplatePath;
 string dbPrjPath = "C:\\source";
 dbTemplatePath = soln.GetProjectItemTemplate("ConsoleApplication.zip", "CSharp");
 soln.AddFromTemplate(dbTemplatePath, dbPrjPath, "New db project", false);

When I replace ConsoleApplication.zip with dbApplication.zip, I could not come up with a database project.

Also, I noticed the template for ConsoleApplication found in the location Microsoft Visual Studio 14.0\\Common7\\IDE\\ProjectTemplates\\CSharp\\Windows Root\\Windows\\1033\\ConsoleApplication whereas there is no such template for database project.

Any help would be appreciated. Thanks in advance

To create an empty database project programmatically, you must need the template of an empty database project.

If such a template is not found in the Visual Studio folder, you can create an empty database project from visual studio and export the project as a template from Projects -> Export Template...

EnvDTE.DTE dte = (EnvDTE.DTE)obj;
dte.Solution.Create(path, name);
var solution = dte.Solution;
solution.AddFromTemplate(templateLocation, name);
dte.ExecuteCommand("File.SaveAll");

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