Question

Does anyone know How to configure Visual Studio 2012 Database Project to Build a deployment .sql file package.

I'm attempting to not have to use the .dacpac as my only deployment option.

e.g. generate a .sql file of all database schema alters.

Was it helpful?

Solution

If you're trying to do this automatically, you'll want to use the SQLPackage command to generate a script. If you want to do this within the IDE, publish the database and choose the option to generate a script instead of publishing the changes.

I'll usually build the project first with msbuild. That will generate a dacpac against which I can run the SQLPackage command.

My batch file looks something like this:

msbuild .\MyDB\MyDB.sqlproj /t:build /p:Configuration="Local"
sqlpackage /a:DeployReport /tsn:FTPROD /sf:.\MyDB\sql\Local\MyDB.dacpac /pr:.\MyDB\Publish\Production.publish.xml /op:.\Release\MyDB-Production.xml
sqlpackage /a:script /tsn:DBServer /sf:.\MyDB\sql\Local\MyDB.dacpac /pr:.\MyDB\Publish\Production.publish.xml /op:.\Release\MyDB-Production.sql

The first line builds the project. The second creates a deploy report so I can easily see what's going to be changed. The last generates the script. Your paths may vary so you'll need to tweak as appropriate for your environment. You'll need to be able to access the database against which the script will be run in order to generate the script.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top