I asked yesterday about getting AfterBuild
working and was able to get that working by placing it at the very bottom of the Project
section: MSBuild AfterBuild Step
I have tried the exact same thing with a different project. This is my BeforeBuild
code:
<Target Name="BeforeBuild">
<Message Text="###HI###" Importance="High" />
</Target>
I don't have another before Target Name="BeforeBuild"
in the project and I have this placed at the very bottom of the Project
section. The .vcxproj is parsing/loading into Visual Studio 2010 without issue. I have my "MSBuild project build output/log verbocity" set to "Normal".
Is there something else I haven't thought of that would cause this not to run?
A target is not called unless called explicitly, is a default target, is declared in DependsOn of a target that is called or declare its own BeforeTargets or AfterTargets and one of those targets is called.
So, if you want a target to be called before a target called "InitializeBuildStatus", you can write it like this:
<Target Name="MyBeforeBuild" BeforeTargets="InitializeBuildStatus">
<Message Text="###HI###" Importance="High" />
</Target>
It'll run if the "InitializeBuildStatus" target runs. (You can enable verbose logging in Visual Studio or for an MSBuild run to help determine the appropriate BeforeTarget targets.)
The "BeforeBuild" and "AfterBuild" targets are called explicitly by the target system of some of Microsoft's project types. That offers only limited extensibility. The newer (.NET 4.0) way is BeforeTargets and AfterTargets.
See Target Build Order.