数据库项目中的预部署

发布于 2024-07-29 13:54:22 字数 468 浏览 0 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一桥轻雨一伞开 2024-08-05 13:54:22

这可能不完全是您想要的,但它可能会帮助您解决问题。 快速浏览后,我认为部署前和部署后脚本的顺序可能很难更改。

据我了解,构建项目中有一些钩子允许您在部署开始之前执行自己的代码。

  1. 在 .dbproj 文件中定义 PreDeployEvent 属性。
  2. 在 .dbproj 文件中定义 BeforeDeploy 目标。

我认为,其中任何一个都应该在正确的时间点执行。

如果您使用 PreDeployEvent 属性,您需要指定要执行的单个命令行。 一个粗略的例子:

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

如果您想要更多控制,请使用 BeforeDeploy 目标,它将允许您运行一个或
更多自定义 msbuild 任务。 这是另一个粗略的例子:

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

顺便说一下,有很多免费的自定义任务,一个例子是 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.

  1. Define a PreDeployEvent property in your .dbproj file.
  2. Define a 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:

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

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

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

By the way, there are plenty of custom tasks freely available, one example being those at www.msbuildextensionpack.com.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文