简体   繁体   English

使用C#以编程方式创建一个空的数据库项目

[英]Create an empty database project programmatically using C#

I wanted to create an empty database project from Visual Studio 2017 programmatically. 我想以编程方式从Visual Studio 2017创建一个空的数据库项目。 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. 当我用dbApplication.zip替换ConsoleApplication.zip时,我无法提出数据库项目。

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. 此外,我注意到在Microsoft Visual Studio 14.0 \\ Common7 \\ IDE \\ ProjectTemplates \\ CSharp \\ Windows Root \\ Windows \\ 1033 \\ ConsoleApplication位置中找到的ConsoleApplication模板,但没有这样的数据库项目模板。

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... 如果在Visual Studio文件夹中找不到这样的模板,则可以从Visual Studio创建一个空的数据库项目,然后从“ 项目”->“导出模板...”中将该项目导出为模板。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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