How can I script the deployment of a Visual Studio database project?

巧了我就是萌 提交于 2019-12-05 00:08:13

问题


How can I script the deployment of a Visual Studio database project?

I have a DB project in visual studio and I would like to use it in order to deploy on remote machines via a script. I notice that when I 'deploy' from visual studio, it generates a .sql file.

I intercepted this file and tried running it from the command line with osql.exe, but I didn't have any success. Should this work, is there a better way to deploy a database programatically from a database project, may be by referencing in another project and calling some method to deploy it?


回答1:


MSBuild /target:SQLBuild MyProjectName.dbproj

Performs a build-only action. It builds only a single database project named MyProjectName.dbproj. The project properties within the .dbproj file are used to assemble the build script.

MSBuild /target:Deploy /property:TargetDatabase=UpdatedTargetDatabase;TargetConnectionString="Data Source=(local)\SQLEXPRESS;Integrated Security=True;Pooling=False" MyProjectName.dbproj

Deploys the database project, overriding the target database name and connection string.




回答2:


For me in Vs2010, this one produced the file

MSBuild /target:Deploy MyProjectName.dbproj

another option is

MSBuild /target:Build;Deploy MyProjectName.dbproj

additional information found at http://ishan-patel.blogspot.com/2012/04/create-single-database-deployment.html



来源:https://stackoverflow.com/questions/2823890/how-can-i-script-the-deployment-of-a-visual-studio-database-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!