SSDT is powered by a library called the Data-Tier Application Framework (also known as DacFX). DacFX is a public API that you can use to extract and publish dacpac files. You can find a copy of DacFX in Program Files under Visual Studio or SQL Server in a directory something like this:
- C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\SQLDB\DAC\130
- C:\Program Files (x86)\Microsoft SQL Server\130\DAC\bin
You can download the latest version of DacFX here:
https://www.microsoft.com/en-us/download/details.aspx?id=51672
Note that when you install DacFX it's also necessary to install its dependencies, SqlSysClrTypes and SqlDom, which can be found in the System Requirements section of the above download page.
To use DacFX to extract and publish a dacpac file, you can use SqlPackage.exe, like so:
C:\Program Files (x86)\Microsoft SQL Server\130\DAC\bin\SqlPackage.exe /a:extract /scs:"Data Source=YOURSERVER;Initial Catalog=YOURDB;Integrated Security=true" /tf:C:\temp\yourdb.dacpac
C:\Program Files (x86)\Microsoft SQL Server\130\DAC\bin\SqlPackage.exe /a:publish /tcs:"Data Source=YOURSERVER;Initial Catalog=YOUROTHERDB;Integrated Security=true" /sf:C:\temp\yourdb.dacpac
Alternately, you can use DacFX programmatically using the Microsoft.SqlServer.Dac API, like so:
using Microsoft.SqlServer.Dac;
class Program
{
static void Main(string[] args)
{
DacServices ds = new DacServices("Data Source=YOURSERVER;Initial Catalog=YOURDB;Integrated Security=true");
ds.Extract(@"C:\temp\yourdb.dacpac", "YOURDB", "AppName", new System.Version());
using (DacPackage dp = DacPackage.Load(@"C:\temp\yourdb.dacpac"))
{
ds.Deploy(dp, "YOUROTHERDB");
}
}
}