How to include data in a DacPac
Years later, I finally figure this out: There are two types of exports:
- DACPAC - which includes only the structure
- BACPAC which includes data and structure.
You can create either from SSMS:
- DACPAC: Select your database, right click for Tasks-> Extract Data Tier App.
- BACPAC: Select database, right click for Tasks-> Export Data Tier App.
This isn't exactly from Visual Studio as you asked but it might be a workaround. If your db exists in a dev server then maybe you can use SqlPackage.exe Export
and Extract
actions:
For Export
By default, data for all tables will be included in the .bacpac file.
A SqlPackage.exe Export action exports a live database from SQL Server or Windows Azure SQL Database to a BACPAC package (.bacpac file). By default, data for all tables will be included in the .bacpac file. Optionally, you can specify only a subset of tables for which to export data. Validation for the Export action ensures Windows Azure SQL Database compatibility for the complete targeted database even if a subset of tables is specified for the export.
sqlpackage.exe /action:Export /TargetFile:"test.bacpac"
/sourceDatabasename:test
/sourceservername:.\testserver
You can import your bacpac
file
https://msdn.microsoft.com/en-us/library/hh710052.aspx
For Extract
Makes a DACPAC with the user table data
sqlpackage.exe /action:Extract /TargetFile:"test.dacpac"
/sourceDatabasename:test
/sourceservername:".\testserver"
/p:ExtractAllTableData=true
If you don't want to use SqlPackage.exe, this article is old but it has three workarounds that might work:
1) Redeploy the same .dacpac file using SSMS's "Upgrade Data-tier application..." wizard under the [Server]/Management/Data-tier Application/[Application Name] node in the SSMS Object Explorer. The upgrade wizard presents presents checkbox options to execute the pre- and/or post-deployment scripts in the .dacpac file. Enabling both the pre- and post-deployment script options, then performing the upgrade will produce the expected result.
2) Manually execute the DACPAC pre- and/or post-deployment T-SQL script files using a SSMS query window, SQLCMD.exe, or simliar. This requires the DACPAC author to ship the pre-/post-deployment scripts alongside the DACPAC file. Alternatively, the pre-/post-deployment scripts can be extracted using the Microsoft DacUnpack.exe utility, or a ZIP file utility (after renaming the file extension from .dacpac to .zip).
3) Use either MSBuild.exe (v4.0.30319.1, or higher) or Visual Studio 2010 Premium SP1 (or higher) to deploy the "SQL Server Data-tier Application" project file. (Exampe: "msbuild /Target:Deploy DeploymentDemo.dbproj").