How to make DACPAC update only one schema?

You can build a deployment using the DacpacMerge library, this will merge the model from the database with the model for a single schema, into a new DacPac. This new generated Dacpac can be deployed without affecting the other objects, as they are the same as the database current definition.


Your two options are as follows:

  1. Copy SqlPackage.exe and the other DAC DLLs to a folder inside your solution, or one controlled by your deployment team. Also copy your contributor DLL to that same folder. Then make sure that when deploying you use SqlPackage.exe from that location. Since any DLL in the same folder as Microsoft.Data.Tools.Schema.Sql.dll will be checked for extensions you can use this method to get your contributor included during deployment, without the need to install to a system-wide location.

  2. Filter out objects related to other schemas from your dacpac, and then deploy with DropObjectsNotInSource = false. This is less ideal since it won't drop objects that you delete, but the benefit is that you can do it at build time / before passing to the deployment team.

Note that this basic topic is covered in the API tutorial I wrote, with some samples of that in this samples project. It sounds like you have option #1 written already (the tutorial has a simplified version that only blocks additions, not alters/drops), but you can see a comparison between them. Also the samples show how to publish using our APIs (this maps directly to using SqlPackage.exe) and how to easily test and validate contributor behavior.