views:

711

answers:

2

I am trying to add some stored procedure to a build process in visual studio (using MSBuild).

I have a database project (*.dbp) added to my solution, however unlike some of the other database projects available in VS i cannot build or run it. ( I believe this is the project file i want as I am using SQL2000)

How can i get the SQL scripts to run as I build the project? I can run the scripts by right clicking and pressing run.

+1  A: 

Database projects are not built like normal projects. If you want to execute scripts inside this project, my advice would be to extend the associated project(s) which are MSBuild compatible (csproj, vbproj, etc.) and reference/execute your scripts from there using your tool of choice.

How you implement it is up to you, for example, you could hook into BeforeBuild target and execute scripts using SqlExecute task.

FWIW, we have to support SQL Server 2000, 2005, 2008+, so the task becomes much harder; think NVarchar(max) (2005+) vs NText (2000+) plus all the sp renames, etc between versions. We also wanted a single script which developers, QA and installer used to ensure consistency. So our approach was a custom tool which allowed token/keyword replacements inside scripts, which provides flexibility between different SQL Server versions and customers installations (e.g. user/login details, db names), as well as integration into various technologies so scripts can run from command line, MSBuild, MSI custom action using Wix projects, or whatever we need them to run from.

Si
A: 

Database projects can be Built.

They cannot be run - they can be Deployed.

When you deploy, the project builds and then deploys. The code will be deployed along with the Pre-Build and Post-Build scripts and the Pre-Deployment and Post-Deployment scripts.

So if you want scripts to run as you BUILD the project, you want to look into the Pre-Build and Post-Build under Build Events in the Project properties.

Raj More