[英]DB Deployment with MsBuild
Anyone got examples of how to do a DB deployment without TFS in MSBuild. 任何人都获得了有关如何在MSBuild中不使用TFS进行数据库部署的示例。 I had automated db deployments in nant at an old position, but need to do it in msbuild at a new job.
我曾在nant的旧位置进行过自动数据库部署,但需要在新工作中的msbuild中进行。 I was using the nant and setting a boolean flag to trigger processing sql files, but im unsure of how to do this in msbuild.
我正在使用nant并设置了一个布尔标志来触发处理sql文件,但是不确定如何在msbuild中执行此操作。 Everything surprising with MSBuild points to TFS
MSBuild的所有令人惊讶之处都指向TFS
I was using the following algorithm 我正在使用以下算法
// Set run updates = false
// Store DB Version from Version Table
// For each file in SQL directory
// if file == db version
// set run updates = true
// else if run updates
// run sql in file
// update db version
I'm open to changes in how this is handled... but can't forsee my company moving to TFS 我对如何处理此问题持开放态度...但是无法预见我的公司将转向TFS
I decided to use DBDeploy to do the database deployments. 我决定使用DBDeploy进行数据库部署。 The following works in my situation.
以下情况适用于我的情况。
<Target Name="DeployDB">
<RemoveDir Directories="$(MSBuildProjectDirectory)\..\temp" ContinueOnError="true" />
<MakeDir Directories="$(MSBuildProjectDirectory)\..\temp" ContinueOnError="true" />
<Exec Command="$(MSBuildProjectDirectory)\..\lib\dbdeploy\example\tools\nant\bin\nant -buildfile:dbdeploy.build -D:DBConnstring="$(MainDatabaseConnectionString)" -D:SQLDirectory=..\DB -D:OutputFile=..\Temp\Deploy.sql" />
<MSBuild.ExtensionPack.SqlServer.SqlExecute TaskAction="Execute" Files="..\Temp\Deploy.sql" ConnectionString="$(MainDatabaseConnectionString)" />
<RemoveDir Directories="$(MSBuildProjectDirectory)\..\temp" ContinueOnError="true" />
</Target>
with a build file of 的构建文件
<?xml version="1.0" encoding="UTF-8"?>
<project name="dbdeploy_example" default="generate-script" basedir="." xmlns="http://nant.sf.net/release/0.85/nant.xsd">
<loadtasks assembly="../lib/DbDeploy/bin/Net.Sf.Dbdeploy.dll" />
<property name="DBConnstring" value="Server=localhost;Initial Catalog=XXXX;Integrated Security=SSPI;" />
<property name="SQLDirectory" value="." />
<property name="OutputFile" value="deploy.sql" />
<property name="UndoOutput" value="deploy-undo.sql" />
<target name="generate-script" description="generate a sql upgrade script">
<echo message="DBConstring: ${DBConnstring}" />
<echo message="SQLDirectory: ${SQLDirectory}" />
<echo message="OutputFile: ${OutputFile}" />
<echo message="UndoOutput: ${UndoOutput}" />
<dbdeploy dbType="mssql"
dbConnection="${DBConnstring}"
dir="${SQLDirectory}"
outputFile="${OutputFile}"
undoOutputFile="${UndoOutput}" />
</target>
</project>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.