Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way in a visual studio database project to exclude certain object during deployment?

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?

like image 253
Jason Avatar asked Aug 03 '10 17:08

Jason


People also ask

What is exclude from project in Visual Studio?

DEF files (one for each configuration if you are generating different names), one often decides to keep a file in the Solution Explorer but code it as “excluded”. This means that the compiler will not process it.

How do you exclude a project from solution build?

On the menu bar, choose Build > Configuration Manager. In the Project contexts table, locate the project you want to exclude from the build. In the Build column for the project, clear the check box. Choose the Close button, and then rebuild the solution.

What does deploy solution do in Visual Studio?

When you deploy a project or solution in Visual Studio, the assemblies are automatically built and deployed into the specified application.


1 Answers

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.

like image 139
Jakub Berezanski Avatar answered Sep 23 '22 17:09

Jakub Berezanski