How can I script the deployment of a Visual Studio database project?
如何编写Visual Studio数据库项目的部署脚本?
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.
我在visual studio中有一个DB项目,我想使用它来通过脚本部署在远程机器上。我注意到当我从visual studio'部署'时,它会生成一个.sql文件。
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?
我拦截了这个文件并尝试使用osql.exe从命令行运行它,但我没有任何成功。如果这有用,是否有更好的方法从数据库项目以编程方式部署数据库,可以通过引用另一个项目并调用某种方法来部署它?
2 个解决方案
#1
4
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.
执行仅构建操作。它只构建一个名为MyProjectName.dbproj的数据库项目。 .dbproj文件中的项目属性用于组装构建脚本。
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
0
For me in Vs2010
, this one produced the file
对于Vs2010中的这个,我生成了这个文件
MSBuild /target:Deploy MyProjectName.dbproj
MSBuild / target:部署MyProjectName.dbproj
another option is
另一种选择是
MSBuild /target:Build;Deploy MyProjectName.dbproj
MSBuild / target:Build; Deploy MyProjectName.dbproj
additional information found at http://ishan-patel.blogspot.com/2012/04/create-single-database-deployment.html
更多信息,请访问http://ishan-patel.blogspot.com/2012/04/create-single-database-deployment.html
#1
4
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.
执行仅构建操作。它只构建一个名为MyProjectName.dbproj的数据库项目。 .dbproj文件中的项目属性用于组装构建脚本。
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
0
For me in Vs2010
, this one produced the file
对于Vs2010中的这个,我生成了这个文件
MSBuild /target:Deploy MyProjectName.dbproj
MSBuild / target:部署MyProjectName.dbproj
another option is
另一种选择是
MSBuild /target:Build;Deploy MyProjectName.dbproj
MSBuild / target:Build; Deploy MyProjectName.dbproj
additional information found at http://ishan-patel.blogspot.com/2012/04/create-single-database-deployment.html
更多信息,请访问http://ishan-patel.blogspot.com/2012/04/create-single-database-deployment.html