0

I have a standard sql server 2008 project which has been created using vs2010. I have been trying to modify the build process so that at the end a custom task should fire which would call VSDBCMD to generate a deploy script by comparing the output of the build (the dbschema file) against a static DBschema file. When I run this command from a VS2010 command prompt

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"

Everything works great and the newdeployment.sql file is generated. However when I modify my .dbproj file and include this as a AfterBuilds Target

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

the build fails with a

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.

message.

Can anyone suggest what I am doing wrong?

Nikhil
  • 3,304
  • 1
  • 25
  • 42

2 Answers2

3

Visual Studio also exposes $(VSTSDBDirectory) - location of VSDBCMD

MSBuild task could look as follows:

<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" />
Haroon
  • 1,052
  • 13
  • 28
1

I managed to solve it. Basically doing this

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

rightly sets the working directory to C:\Program Files(x86)....where my VersionedSchemas\v1.0.dbschema etc. don't exist. The trick was to keep the working directory same as the ProjectDirectory and still call VSDBCMD. I managed this by doing

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

The trick was to use & quot; around C:\Pro...

Nikhil
  • 3,304
  • 1
  • 25
  • 42