Visual Studio 数据库项目中有没有办法在部署期间排除某些对象?
我有一个场景,我使用 Visual Studio 2010 数据库项目将更改部署到多个数据库安装,但在某些数据库安装中,我想从该副本中排除一组视图。有没有办法使用构建配置来排除这些视图的部署?
I have a scenario where I am using a visual studio 2010 database project to deploy changes to multiple database installations, but on certain ones I want to exclude a set of views from that copy. Is there a way using build configurations to exclude these views from being deployed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我最终编写了一个自定义部署计划修改器,使用 sqlcmd 变量进行控制,指定在部署期间不应触及的对象。每个数据库项目配置可能引用一组不同的变量(.sqlcmdvars 文件) - 这可以在项目属性中的“部署”选项卡上设置。
计划修改器检查部署计划并删除创建/修改/删除应忽略的对象的步骤。我们使用它来忽略数据文件(在不同的暂存环境中具有不同的名称)、一些备份表和一些我们未保留在数据库项目中的对象类型(用户、角色成员资格、数据库级别权限)。该功能与架构比较配置(忽略对象类型)类似(但粒度更细),但它在部署期间工作(也适用于 VSDBCMD)。
“编写自定义部署计划修改器”部分听起来可能工作量很大,但实际上很简单,包括学习和测试部分,我花了不到一天的时间。 MSDN 上有一个非常有用的演练。
I ended up writing a custom deployment plan modifier, controlled using sqlcmd variables specifying objects that should not be touched during deployment. Each database project configuration may reference a different set of those variables (a .sqlcmdvars file) - this can be set on the Deploy tab in the project properties.
The plan modifier inspects the deployment plan and deletes steps that create/modify/delete objects which should be ignored. We are using it to ignore data files (which have different names on various staging environments), some backup tables and a few types of objects we do not keep in the DB project (users, role memberships, database level permissions). The functionality is similar (but finer-grained) to Schema Comparison configuration (ignored object types), but it works during deployment (also with VSDBCMD).
The "write a custom deployment plan modifier" part may sound like a lot of work, but actually it is quite simple, it took me less than a day, including the learning and testing parts. There is a very helpful walkthrough on MSDN.
您是否尝试过创建复合项目?我自己还没有实现这个场景,但您似乎可以:
因此,在部署project1时,将不包括视图,而在部署project2时,将包括视图和核心对象。
请查看以下 Microsoft 链接。特别是标题为“组合项目的使用和限制”的部分
http://msdn。 microsoft.com/en-us/library/dd193405.aspx
Have you tried creating a composite project? I haven't implemented this scenario myself but it would seem you could:
Thus when deploying project1, the views would not be included and when deploying project2, the views as well as the core objects would be included.
Have a look at the following Microsoft link. In particular the section titled "Uses and Limitations of Composite Projects"
http://msdn.microsoft.com/en-us/library/dd193405.aspx