質問

Using sqlpackage with Action=Script, I get a deployment script. But I don't get any copies of the scripts with property Copy To Output Directory = Copy always.

However, when publishing from within Visual Studio, I do get these files.

Why is that? By design?

I want to trigger a build using sqlpackage (or something else), including these scripts..

役に立ちましたか?

解決

We're using something like this:

msbuild .\DBName\DBName.sqlproj /t:build /p:Configuration="Local"

sqlpackage /a:script /tsn:TargetServer /sf:.\DBName\sql\Local\DBName.dacpac /pr:.\DBName\Publish\TargetServer.publish.xml /op:.\Scripts\DBName-TargetServer.sql

(where TargetServer and DBName make sense for your projects and the dacpac was just built) /a:Script - action == generate script /sf - dacpac for source /pr - Publish Profile to use /op - output filename

I usually combine that with the following to get a deploy report for changes:

sqlpackage /a:DeployReport /tsn:ServerName /sf:.\DBName\sql\Local\DBName.dacpac /pr:.\DBName\Publish\ServerName.publish.xml /op:.\Scripts\DBName-ServerName.xml

他のヒント

SqlPackage.exe works against Dacpac files such as the one built by your project. That's intended to be a single artifact containing all of the information needed to deploy your schema to a database. It doesn't have any knowledge of anything that's not in the dacpac so that's why using a:/script doesn't produce those files.

If you want to include some scripts as part of the deployment why not mark them as pre or post-deployment scripts? That will incude them in the dacpac and automatically execute them during publish. If you have multiple scripts you can write one main script and use the ":r filename" SQLCMD command to pull in the other script contents. At build time a single merged postdeployment.sql script is created and saved in the dacpac - you can actually see the contents by renaming the file to a .zip which can help you understand what SqlPackage and other tools will work with.

As mentioned by @Peter-Schott in the other answer, you can call msbuild from the command line to actually build the project and even to publish the project directly if you use the /t:publish command.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top