I found the most effective way to solve this problem, is set assign a special property called TargetsTriggeredByCompilation
to a desired target that you want to call after core compile is complete.
Core compile is skipped with incremental builds, with that I've set separate property SkipPostBuildActions
to true
at the start of the build. This is then further used as condition in any targets which I want to be conditional on core compile.
Once core compile is complete, it will trigger my EnablePostBuild
target, this target intern sets SkipPostBuildActions
to false
. This then enables subsequent build targets.
<!-- Defines Targets that should be run after Compile, but skipped if Compile doesn't take place -->
<PropertyGroup>
<TargetsTriggeredByCompilation>
$(TargetsTriggeredByCompilation);
EnablePostBuild
</TargetsTriggeredByCompilation>
</PropertyGroup>
<Target Name="EnablePostBuild">
<!-- Disable post build actions -->
<PropertyGroup>
<SkipPostBuildActions>false</SkipPostBuildActions>
</PropertyGroup>
</Target>
An example of '$(SkipPostBuildActions)' == 'false'
used on a NugetProject
target:
<!-- Creating Nuget Packages -->
<Target Name="NugetProject" AfterTargets="PostBuild" Condition="'$(NugetProject)' == 'true' And '$(SkipPostBuildActions)' == 'false'" DependsOnTargets="GetVersion">
<!-- Manages getting the assembly version for output folders -->
<Message Importance="High" Text="Current Assembly Version $(GitVersion_NuGetVersion)"/>
<!-- Note the Exec Task needs to provide a path relative to current Project that is building -->
<Exec Command="$(ToolsPath)NuGet.exe pack -Version $(VersionStamp) -Symbols -SymbolPackageFormat snupkg -IncludeReferencedProjects -OutputDirectory $(LocalMachineNugetPath) -Verbosity detailed -Properties Configuration=$(Configuration)"/>
</Target>
TargetsTriggeredByCompilation
is triggered with a call target deep in the internals of the Targets graph that is pulled in with default build.