1

Goal: Run custom action after publishing SQL server database project in visual studio 2017

Problem: I have a SQL Server Database Project (.sqlproj) in the solution. In order to execute a customer action after publishing the project, the .sqlproj file is modified by adding a new target as shown below.

AfterPublish target

When I publish the project by right clicking on the project (or publish profile in the project) in visual studio IDE, it publishes the database project, but it does not execute this AfterPublish target.

Note: If I publish using MSBuild as shown below it successfully executes AfterPublish target.

msbuild mydbproj.sqlproj /t:build;publish /p:sqlpublishprofilepath=mydbproj.publish.xml
101V
  • 492
  • 1
  • 6
  • 13

1 Answers1

1

When I publish the project by right clicking on the project (or publish profile in the project) in visual studio IDE, it publishes the database project, but it does not execute this AfterPublish target.

According to your description, I have also got the same issue. Since there is no detail log output for publishing of SQL Server Database Project, so I add a simple copy task in the target to confirm that the AfterPublish target has not been executed:

  <Target Name="AfterPublish">
    <Message Text="Test After Publish Target" Importance="high">
    </Message>
    <Copy SourceFiles="D:\Test.txt" DestinationFolder="D:\Test" />
  </Target>

Then I got the same issue, the test file Test.txt only copied when I publish project via MSBuild command line.

Besides, in order to narrow the scope of this issue, I created a Windows Forms Application project with the same AfterPublish target. It works fine in Visual Studio and MSBuild command line.

So this issue is more related to SQL Server Database Project type, I have submit this issue to Developer Community:

https://developercommunity.visualstudio.com/content/problem/143641/afterpublish-target-not-work-for-sql-server-databa.html

You can follow with your comments and check the feedback of this issue.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • @101V, I also help you vote, if possible, you could also add your comment and vote it. For this so case, if possible, you could mark leo suggestion as the temporary answer, so other community member who get the same issue could find the feedback easily. We will also follow up that feedback in our side, if we get any update, we will share it here. – Jack Zhai Nov 09 '17 at 05:22