Project "Pre-Deployment in the Database"

Visual Studio 2008 Database Project for SQL Server 2008

The project has placeholders for SQL scripts before and after deployment. They work - well, in most cases anyway.

The project has the Always-Recreate-Database option: discard the existing database and create a new hot database every time.

When deploying my database, the entire SQL Script is created and executed.

My database is used for replication, and as part of the Post-Deployment script, I designate the server as a distribution, create replication, and add articles to it.

Therefore, I need to disable replication. And the logical place to put in Pre-Deploy.

VS2008 pretty quickly wiped a smug grin. If the Always-Recreate-Database is checked, then it places the Script to delete and recreate the database, then it places my pre-deployment script, and then everything else.

Is there a way to modify the database project template so that SQL scripts are executed before deployment, where they are intended to be executed - before any deployment occurs.

+6
sql sql-server visual-studio-2008 database-project
source share
2 answers

This may not be exactly what you need, but it can help you solve your problem. after a quick look, I think that alternating scenarios before and after deployment can be too difficult to change.

As I understand it, there are some interceptors in the build project that will allow you to execute your own code before the deployment begins.

  • Define the PreDeployEvent property in the PreDeployEvent file.
  • Define the BeforeDeploy target in the .dbproj file.

Any of these should be done at the right time, I think.

If you use the PreDeployEvent property, you need to specify one command line that will be executed. A rough example:

 <PropertyGroup> <PreDeployEvent>sqlcmd.exe -i myscript.sql</PreDeployEvent> </PropertyGroup> 

If you need more control, use the BeforeDeploy target, which will allow you to run one or more msbuild custom tasks. Here is another example:

 <Target Name="BeforeDeploy"> <Message Text="BeforeDeploy" Importance="high" /> </Target> 

By the way, there are many custom tasks that are available, for example, at www.msbuildextensionpack.com .

+3
source share

Please also check out this article Preliminary Deployment Scenarios

+2
source share

All Articles