Visual Studio makes it relatively easy to hook in to pre and post build events, by using the Project properties tab named Build Events. However when using Database Projects (.dbproj) you more often need to do something at deployment time. The good news is that the standard MSBuild framework, already defines these events, the bad news is that you manually have to update the project file yourself.
The steps are pretty simple:
1: <Target Name="PreDeployEvent">
2: <Message Importance="high" Text="Pre deployment event"/>
3: </Target>
4:
5: <Target Name="PostDeployEvent" >
6: <Message Importance="high" Text="Post deployment event"/>
7: </Target>
1: ------ Build started: Project: nw, Configuration: Debug Any CPU ------
2: Loading project references...
3: Loading project files...
4: Building the project model and resolving object interdependencies...
5: Validating the project model...
6: Writing model to nw.dbschema...
7: nw -> D:\demo\nw\sql\debug\nw.dbschema
8: ------ Deploy started: Project: nw, Configuration: Debug Any CPU ------
9: Pre deployment event
10: Deployment script generated to:
11: D:\demo\nw\sql\debug\nw.sql
12:
13: The deployment script was generated, but was not deployed. You can change the deploy action on the Deploy tab of the project properties.
14: Post deployment event
15: ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========
16: ========== Deploy: 1 succeeded, 0 failed, 0 skipped ==========
Now you should be able to hook-up your events to the pre and post deployment events. Please keep in mind that pre-deployment scripts do not change the outcome of deployments like discussed earlier in this blog post.
Success, GertD @ DBProj.com