We can use SSMS to export data-tier application for an SQL Server database. I've been using this method for several years on my local machine.

However, to make things work under automated environments, like CI/CD environments, or some automated scheduled tasks. We usually need to do it under the command line. 

Microsoft has provided a cross-platform command-line tool that can import/export DAC: sqlpackage.exe

It's written in .NET and currently in preview for Linux and macOS. For Windows, you can download and install it here: https://go.microsoft.com/fwlink/?linkid=2087429 

It installed to C:\Program Files\Microsoft SQL Server\150\DAC\bin, but it doesn't add to the PATH environment variable yet. So, in order to use it, we have to manually switch to the installation directory first. Or perhaps we should configure it to PATH on a server.

To export a data-tier application, specify 3 parameters:

  1. /Action:{Extract|DeployReport|DriftReport|Publish|Script|Export|Import} Specifies the action to be performed. (short form /a), we will only use Export in this example.
  2. /SourceConnectionString:<string>Specifies a valid SQL Server/Azure connection string to the source database. If this parameter is specified it shall be used exclusively of all other source parameters. (short form /scs)
  3. /TargetFile:<string> Specifies a target file (i.e., a .dacpac files) to be used as the target of action instead of a database. If this parameter is used, no other target parameter shall be valid. This parameter
    shall be invalid for actions that only support database targets. (short form /tf)

Example:

SqlPackage.exe /a:export /scs:"Server=(local);Database=moonglade-dev;Trusted_Connection=True;" /tf:"D:\moonglade-dev-20190520.bacpac"

And my bacpac file is there: