visual-studio-2010sql-server-2008vsdbcmd

Calling VSDBCMD from inside a dbproj file


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?


Solution

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