Search code examples
sql-servercontinuous-integrationsql-server-data-toolscontinuous-deploymentsqlpackage

SSDT generate and publish database changes


I am currently using the following command to generate a database script using SSDT:

"C:\Program Files\Microsoft SQL Server\150\DAC\bin\SqlPackage.exe" /Action:Script /sf:DB.dacpac /Profile:publish.xml /op:Script.sql

and the following command to publish:

"C:\Program Files\Microsoft SQL Server\150\DAC\bin\SqlPackage.exe" /Action:Publish /sf:DB.dacpac /Profile:publish.xml 

Is there anyway we can merge them so it can generate a script (for audit purpose) as well as publish on the database?


Solution

  • Yes, it is quite recent but when you publish you can also use "/DeployScriptPath:" and give it a path and it will save the script.

    Older versions of SSDT you had to do exactly what you are doing but we can now use this to do it in one step.

    This will have the latest sqlpackage.exe in case you need it:

    https://www.nuget.org/packages/Microsoft.Data.Tools.Msbuild/

    ed