2010-11-08 102 views
1

任何人都有如何在MSBuild中沒有TFS的情況下進行數據庫部署的例子。我在舊的位置進行了自動數據庫部署,但需要在新作業中在msbuild中執行。我正在使用nant並設置一個布爾標誌來觸發處理sql文件,但我不確定如何在msbuild中執行此操作。令人驚訝的一切與MSBuild的點TFS使用MsBuild進行數據庫部署

我用下面的算法

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

回答

2

我決定使用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=&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> 
構建文件