2012-02-17 42 views
0

我有一個使用vs2010創建的標準sql server 2008項目。我一直在嘗試修改構建過程,以便在最後啓動一個自定義任務,通過將構建的輸出(dbschema文件)與靜態DBschema文件進行比較來調用VSDBCMD以生成部署腳本。當我從VS2010命令提示符下運行此命令從dbproj文件內部調用VSDBCMD

vsdbcmd.exe /a:deploy /dd:- /dsp:sql /model:obj\Release\EnterpriseBuild.Services.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase="EnterpriseBuild.Database" 

一切都很正常,併產生newdeployment.sql文件。然而,當我修改我的.dbproj文件,包括以此爲目標AfterBuilds

<Target Name="AfterBuild"> 
    <!--<Message Text="sample text" Importance="high"></Message>--> 
    <Exec IgnoreExitCode="false" 
      WorkingDirectory="C:\Program Files (x86)\Microsoft Visual Studio 10.0\VSTSDB\Deploy\" 
      Command="vsdbcmd.exe /a:deploy /dd:- /model:obj\Release\EnterpriseBuild.Services.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase=&quot;EnterpriseBuild.Database&quot;" /> 
    </Target> 

構建失敗了

EnterpriseBuild.Services.Database.dbproj(211,5): error MSB3073: The command "vsdbcmd.exe /a:deploy /dd:- /model:obj\Release\EnterpriseBuild.Services.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase="EnterpriseBuild.Database"" exited with code 1. 

消息。

任何人都可以建議我做錯了什麼?

回答

1

我設法解決它。基本上,這樣做

<Target Name="AfterBuild"> 
    <!--<Message Text="sample text" Importance="high"></Message>--> 
    <Exec IgnoreExitCode="false" 
      WorkingDirectory="C:\Program Files (x86)\Microsoft Visual Studio 10.0\VSTSDB\Deploy\" 
      Command="vsdbcmd.exe /a:deploy /dd:- /model:obj\Release\EnterpriseBuild.Services.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase=&quot;EnterpriseBuild.Database&quot;" /> 
    </Target> 

正確地設置工作目錄爲C:\ Program Files文件(x86)的......在我的VersionedSchemas \ v1.0.dbschema等不存在。訣竅是保持工作目錄與ProjectDirectory相同,並仍然調用VSDBCMD。我管理這個做

<Exec IgnoreExitCode="false" Command="&quot;C:\Program Files (x86)\Microsoft Visual Studio 10.0\VSTSDB\Deploy\vsdbcmd&quot; /a:deploy /dd:- /model:obj\Release\EnterpriseBuild.Database.dbschema /targetmodelfile:VersionedSchemas\v1.0.dbschema /DeploymentScriptFile:NewDeploymentScript.sql /p:TargetDatabase=&quot;EnterpriseBuild.Database&quot;" /> 

訣竅是使用& QUOT;圍繞C:\臨...

3

Visual Studio中也暴露出$(VSTSDBDirectory) - VSDBCMD

的位置

MSBuild任務可以看看如下:

<Exec Command="&quot;$(VSTSDBDirectory)\Deploy\VSDBCMD&quot; /a:Deploy /q+ /dd:+ /dsp:sql /manifest:&quot;$(OutDir)Database.deploymanifest&quot; /cs:&quot;Integrated Security=SSPI;Persist Security Info=False;Data Source=(local)&quot; /p:AlwaysCreateNewDatabase=true /p:CommentOutSetVarDeclarations=false /p:TargetDatabase=&quot;MyDatabase&quot; /Script:&quot;$(OutDir)MyDatabase.sql&quot;" ContinueOnError="false" />