使用 MsBuild 进行数据库部署

发布于 2024-09-30 20:58:32 字数 504 浏览 1 评论 0原文

任何人都可以获得有关如何在 MSBuild 中不使用 TFS 进行数据库部署的示例。我在旧位置的 nant 中进行了自动化数据库部署,但需要在新工作的 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

Anyone got examples of how to do a DB deployment without TFS in MSBuild. I had automated db deployments in nant at an old position, but need to do it in msbuild at a new job. 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. Everything surprising with MSBuild points to 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深府石板幽径 2024-10-07 20:58:32

我决定使用 DBDeploy 进行数据库部署。以下内容适用于我的情况。

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

构建文件为

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

I decided to use DBDeploy to do the database deployments. 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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文