How to run different pre and post SSDT pubish scripts depending on the deploy profile

前端 未结 3 648
终归单人心
终归单人心 2021-01-13 20:10

I am using SSDT in Visual Studio 2013.

I have created some pre and post publish scripts for the development server. The pre-deployment scripts empty data from tables

3条回答
  •  终归单人心
    2021-01-13 21:05

    I would suggest to use SQLCMD Variables for your conditional script execution.

    If right-click on a DB project and choose Properties, there is a tab "SQLCMD Variables"

    Enter "$(ServerName)" as variable and something as default value.

    Then you need to open your EVERY .publish.xml in XML editor to insert the following code after PropertyGroup part:

    
        
            [YourVersionOfServer]
        
    
    

    [YourVersionOfServer] should be equal to the result of @@servername on each of your servers.

    The final .publish.xml might look like:

    Then you should wrap you conditional code in pre and post deployment files with:

    if @@servername = '$(ServerName)'
    begin
        ... code for specific server
    end
    

    Thus you can guarantee that the right code hits the right server

提交回复
热议问题