Wade
Wade

Reputation: 356

How to wire up SSDT post-publish command in VS2012 for database project

The goal is to wire up a target or command (e.g. arbitrary executable) to be run after a database project is successfully published from within Visual Studio 2012 user interface using the Publish menu option from the database project context menu (by right-clicking the database project in Solution Explorer and selecting Publish). We have an existing, custom data loader program that bulk loads data from XML files (dumped from master databases) and it would be very convenient to continue using this existing approach. We cannot use the post-deployment SQL file to load data because it will take far too long to load and is difficult to maintain (manual). The data we are loading is a large amount of configuration data that is required by the application and is not the transactional data of the application (which is even larger).

We are currently using Microsoft Visual Studio Ultimate 2012, 11.0.60610.01 Update 3 and SQL Server Data Tools 11.1.30618.1. The database project was created using the database project template in VS2012 (.sqlproj). We are publishing to both SQL Server 2008 R2 and SQL Server 2012. We do know about the SSDT MSBuild targets file that is included in the sqlproj file and its contents. It seems that none of the Deploy or Publish targets defined in this file are executed by VS2012 during a "Publish" command. The Build targets, however, are executed when the project is built from within VS2012.

Here's what we have tried so far with no luck (each item below was attempted one-at-a-time, in isolation):

  1. Wired up the executable command to the PostPublishEvent (similar to the PostBuildEvent).
  2. Wired up the executable command to the PostDeployEvent (similar to the PostBuildEvent).
  3. Wired up a new, custom target that depends on the AfterPublish target that executes the command.
  4. Wired up a new, custom target that depends on the AfterDeploy target that executes the command.
  5. Override the AfterPublish target in the sqlproj file.
  6. Override the AfterDeploy target in the sqlproj file.
  7. Override the SqlPublish target in the sqlproj file.

If I use any of the above "Publish" methods and execute the Publish target using MSBuild, everything works as expected. If I use the "Publish" user interface command in VS2012, the custom command is never executed. If I wire up the custom command to the PostBuildEvent, it runs via MSBuild and VS2012.

It seems that VS2012 is using different means to publish database projects and is not wired into the SSDT MSBuild targets except for the Build target.

Is there a clean way to wire up an arbitrary command that is executed after the "Publish" command, invoked from the VS2012 user interface, completes, ideally, successfully?

I am also aware of this post, Publish data with SSDT?, but this is not an acceptable approach relative to the existing methods used before VS2012.

Thanks!

Upvotes: 2

Views: 932

Answers (1)

The Real Edward Cullen
The Real Edward Cullen

Reputation: 438

I've looked into this too.

From what I can tell, when you use Publish... from the VS 2012/2013 context menu, VS is instantiating a SSDT SqlPublishTask directly, rather then using the common system definitions, presumably so they can integrate it into the "Data Tools" window.

Only solution I can think of is to write an extension that provides a (context) menu item, which would allow you to invoke MSBuild with the target of your choice. The Extension SDK reference seems to have everything you need to get started, while the MSBuild API reference can be found on MSDN.

(A quick search revealed no such existing extension.)

Unfortunately, I don't have access to VS Pro, so can't DiM :(.

Upvotes: 1

Related Questions