Reputation: 3101
Visual Studio 2012. SQL Server Database Project.
Four build configurations were created in solution: Debug, DevDb, TestDb, LocalDb.
Three publish profiles were created in project: DevDb.publish.xml, TestDb.publish.xml, LocalDb.publish.xml
Pushing F5 button (!) I want to:
To do this I edit project (.sqlproj) xml, trying to catch a call of the Deploy target and replace the standart Deploy target with a custom behavior:
<Target Name="Deploy">
<!-- The first statment is for Debug configuration -->
<MSBuild Condition=" '$(Configuration)' == 'Debug' "
Targets="Deploy"
Projects="$(MSBuildProjectFile)"
Properties="Configuration=$(Configuration);"
/>
<!-- The second statement is for DevDb, TestDb, LocalDb configurations -->
<MSBuild Condition=" '$(Configuration)' != 'Debug' "
Targets="SqlPublish"
Projects="$(MSBuildProjectFile)"
Properties="SqlPublishProfilePath=$(Configuration).publish.xml;
Configuration=$(Configuration);"
/>
</Target>
The second statement works fine and I get deployment to the right destination.
The problem is with the first statement - it produces a circular dependency.
error MSB4006: There is a circular dependency in the target dependency graph involving target "Deploy".
My question is: how to intersect (catch and replace) the standart target and if it's required to invoke the standart target again?
Or am I trying to reinvent the wheel and there is another way to do what I want? (What I want is described above under words "Pushing F5 button" :)
Upvotes: 2
Views: 2667
Reputation: 3101
I think I've got the solution.
So if we put such a PropertyGroup with Condition and a custom Target to the end of database project xml file:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
----------- Skip -----------
<PropertyGroup Condition=" '$(Configuration)' != 'Debug' and Exists('$(Configuration).publish.xml')">
<DeployDependsOn>
PublishDatabase
</DeployDependsOn>
</PropertyGroup>
<Target Name="PublishDatabase"> <!-- Custom Target -->
<Message
Text="Deploy is replaced with SqlPublish for configuration = $(Configuration)"
Importance="high" />
<MSBuild
Targets="SqlPublish"
Projects="$(MSBuildProjectFile)"
Properties="SqlPublishProfilePath=$(Configuration).publish.xml;
Configuration=$(Configuration);" />
</Target>
</Project>
we will get the following behaviour:
Upvotes: 3