数据库项目中的预部署
SQL Server 2008 的 Visual Studio 2008 数据库项目
该项目具有用于部署前和部署后 SQL 脚本的占位符。 它们确实有效——嗯,至少大多数时候都是这样。
该项目有一个始终重新创建数据库的选项:删除现有数据库并每次创建一个新的现成数据库。
当我部署数据库时,整个 SQL 脚本被组合在一起并执行。
我的数据库用于复制,作为部署后脚本的一部分,我将服务器指定为分发版,创建复制并向其添加文章。
因此,我必须关闭复制。 放置它的合理位置是在预部署中。
VS2008 很快就让我脸上的得意笑容消失了。 如果选中 Always-Recreate-Database,那么它会放置脚本以删除并重新创建数据库,然后放置我的预部署脚本,然后放置其他所有内容。
有什么方法可以更改数据库项目的模板,以便在发生任何部署之前在其应执行的位置执行预部署 SQL 脚本。
Visual Studio 2008 Database project for SQL Server 2008
The project has placeholders for Pre-Deployment and Post-Deployment SQL scripts. They work - well, most of the time anyways.
The project has an option to Always-Recreate-Database: drop the existing database and create a fresh hot-from-the-oven database every time.
When I deploy my database the entire SQL Script is put together and executed.
My database is used for replication, and as a part of the Post-Deployment script, I designate the server as a distribution, create the replication and add articles to it.
Therefore, I have to shut off replication. And the logical place to put that was in the Pre-Deploy.
VS2008 wiped the smug grin off my face pretty quickly. If Always-Recreate-Database is checked then it puts the script to drop and recreate the database, then puts my Pre-Deployment script, and then everything else.
Is there any way for me to change the template of the database project so that the Pre-Deployment SQL scripts are executed where they are meant to execute - before any deployment occurs.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这可能不完全是您想要的,但它可能会帮助您解决问题。 快速浏览后,我认为部署前和部署后脚本的顺序可能很难更改。
据我了解,构建项目中有一些钩子允许您在部署开始之前执行自己的代码。
PreDeployEvent
属性。BeforeDeploy
目标。我认为,其中任何一个都应该在正确的时间点执行。
如果您使用
PreDeployEvent
属性,您需要指定要执行的单个命令行。 一个粗略的例子:如果您想要更多控制,请使用
BeforeDeploy
目标,它将允许您运行一个或更多自定义 msbuild 任务。 这是另一个粗略的例子:
顺便说一下,有很多免费的自定义任务,一个例子是 www.msbuildextensionpack 中的任务。 com。
This might not be exactly what you're after but it might help you to work around your problem. after a quick look, I think the sequencing of the pre- and post- deployment scripts might be too difficult to change.
As I understand it, there are some hooks in the build project that will allow you to execute your own code before the deployment begins.
PreDeployEvent
property in your .dbproj file.BeforeDeploy
target in your .dbproj file.Either of these should be executed at the right point in time, I think.
If you use the
PreDeployEvent
property you'll need to specify the single command line to be executed. A crude example:If you want more control, use the
BeforeDeploy
target which will allow you to run one ormore custom msbuild tasks. Here's another crude example:
By the way, there are plenty of custom tasks freely available, one example being those at www.msbuildextensionpack.com.