我想大概就这些了,有什么不清楚的请追问:)编辑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 and re-set all the auto identity fields. The post-deployment scripts populate the tables with static and sample data.Now I need to publish the database to our staging and live database servers. I have created new "publish.xml" profiles for these servers. But obviously I don't want the same pre and post scripts to run.How can I either specify different scripts depending on the publish profile, or make the scripts aware of the target and perform different actions.My biggest concern is publishing to the live server and accidentally destroying data.Thanks in advance.Doug 解决方案 You have a few options:1 - Wrap your data changes in calls to @servername or something unique to the environment so you would have something like:if @@servername = 'dev_server'begin delete blah insert blahend2 - You can also achieve something similar using sqlcmd variables, pass in a variable called "/v:DestoryData=true" or something and then you can reference that in your script.3 - Don't use pre/post deploy scripts but have your own mechanism for running them i.e. use a batch file to deploy your dacpacs and add a call to sqlcmd before and after - the downside to this is that when deploying, changes to a table result in any foreign keys being disabled before the pre-deploy and re-enabled after the post-deploy.4 - Edit the dacpacs, the pre/post deploy scripts are just text files inside the dacpac which is essentially a zip file that follows the microsoft packaging format and there is a .net packaging api to let you modify it.I think that is about it, please ask if anything is unclear :)ed 这篇关于如何根据部署配置文件运行不同的前后 SSDT 发布脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 09-02 23:50