Search code examples
c#.netsql-server-data-toolsdacpacdac

Convert publish profile file (.xml) into DacDeployOptions class


I am working on a C# project where I should deploy few .dacpac files so I have used the Microsoft.SqlServer.DacFx library (github from DacFx here).

I have used also in another part the SqlPackage.exe executable to deploy another .dacpac files (no relation between them), so I'm using a publish profile (.xml / .pubxml file) to configure the deployment options. The cmd command looks like this:

SqlPackage /Profile:"Database.publish.xml"

I would need to deserialize this .xml file into a DacDeployOptions class in order to use the same pulish profile when publishing the dacpacs, but as much as I have been able to search I can't find a way to do it. I would appreciate some help with this.

Thanks 😃


Solution

  • After a long search I found the solution. Here the needed Code:

    DacProfile profile = DacProfile.Load(@"C:\temp\publish.xml");
    PublishOptions options = new PublishOptions();
    options.GenerateDeploymentReport = true;
    options.GenerateDeploymentScript = true;
    options.DeployOptions = profile.DeployOptions;