使用MsBuild进行数据库部署

使用MsBuild进行数据库部署,msbuild,continuous-integration,Msbuild,Continuous Integration,任何人都有在MSBuild中如何在没有TFS的情况下进行DB部署的示例。我在nant的一个旧位置进行了自动db部署,但需要在新作业的msbuild中进行。我正在使用nant并设置布尔标志来触发处理sql文件,但我不确定如何在msbuild中执行此操作。MSBuild的所有令人惊讶之处都指向TFS 我使用了下面的算法 // Set run updates = false // Store DB Version from Version Table // For each file in SQ

任何人都有在MSBuild中如何在没有TFS的情况下进行DB部署的示例。我在nant的一个旧位置进行了自动db部署,但需要在新作业的msbuild中进行。我正在使用nant并设置布尔标志来触发处理sql文件,但我不确定如何在msbuild中执行此操作。MSBuild的所有令人惊讶之处都指向TFS

我使用了下面的算法

//  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
我对如何处理这件事持开放态度。。。但我无法预见我的公司将迁移到TFS,我决定使用TFS进行数据库部署。在我的情况下,以下方法有效

  <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=&quot;$(MainDatabaseConnectionString)&quot; -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>

使用的生成文件

<?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>