We have some automated dacpac deployment code that handles both CreateNewDatabase correctly and simply updates database scripts in C # using Microsoft.SqlServer.Dac
Now, in the case of CreateNewDatabase, we want to be able to run DacServices.Deploy() with the Pre and Post Deployment scripts disabled. That is, they should not be executed in this scenario.
I tried to find a suitable place in the DacDeployOptions and DacServices , but I can not find anything that would do this.
Question 1 : I would like something like DacDeployOptions.IgnorePreDeploymentScript = true Are there any means by which I could achieve this at runtime?
Alternatively, some time ago I remember seeing a sample code that showed how to traverse dacpac and create a new dacpac at runtime. I think this approach would allow me to simply create a new dacpac, which I could pass to Deploy, and which would exclude Pre and Post Deployment scripts. I do not like this solution, but it will allow me to achieve what I need.
Question 2 . Can someone point me to some examples of this?
My code is:
var dacService = new DacServices(ConstDefaultConnectionString); using (var dacPackage = DacPackage.Load(dacPacFilePath)) { var deployOptions = new DacDeployOptions { CreateNewDatabase = true, IncludeTransactionalScripts = false }; dacService.Deploy(dacPackage, TestDatabaseName, true, deployOptions); }
Question related to: Creating LocalDB for testing from a Visual Studio SQL project
source share