Back in November I wrote about a quick-and-dirty way to add custom build process into the standard Visual Studio build by overriding pre-defined targets that exist in Microsoft.Common.Targets. While this method works fine for internal build processes it can be brittle if you’re trying to deploy your build process to other teams or customers. In particular, if someone else decides to go and override the same target after you’ve done so, your customization will disappear. To handle this situation we’ve provided a second way of inserting your custom build process into the Visual Studio build: overriding properties that are used in TargetDependsOn attributes. The easiest way to understand how to do this is to look at a short snippet from Microsoft.Common.Targets:
<Target Name="Build" DependsOnTargets="$(BuildDependsOn)"/>
Notice how the Build target has a DependsOnTargets that points to the BuildDependsOn property. That means before the Build target can run, all the targets listed in BuildDependsOn have to run first:
<PropertyGroup>
<BuildDependsOn>
BeforeBuild;
CoreBuild;
AfterBuild
</BuildDependsOn>
</PropertyGroup>
If you want to add something to the build process that runs after everything else in the build, you’d simply create your own target and then add it to BuildDependsOn like this:
$(BuildDependsOn);
MyCustomTarget
<Target Name="MyCustomTarget">
<Message Text="Hello from MyCustomTarget"/>
</Target>
Notice how we’ve included the original value of BuildDependsOn in our new definition of the property. Using this pattern means that anyone who overrides the existing meaning of BuildDependsOn will include all the existing content of the property, without overwriting customizations others have made. You can use a similar approach to get your custom target to run before everything in BuildDependsOn.
Here’s a list of the most commonly used *DependsOn properties:
In addition to the three common properties there are many other properties that are almost never used. For completeness, here’s what they are and why you might use them:
[ Author: Neil Enns ]