且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我怎么能脚本一个Visual Studio数据库项目的部署?

更新时间:2023-02-04 13:25:55

 的MSBuild /目标:SQLBuild MyProjectName.dbproj
 

执行构建-只有行动。它建立只有命名MyProjectName.dbproj一个单一的数据库项目。在.dbproj文件中的项目属性用于组装构建脚本。

 的MSBuild /目标:部署/属性:TargetDatabase = UpdatedTargetDatabase; TargetConnectionString =数据源=(本地)\ SQLEX $ P $干燥综合征;集成安全性= TRUE;池=假MyProjectName .dbproj
 

部署数据库项目,覆盖目标数据库名称和连接字符串。

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?

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.