Here’s roughly what you’ll find in Microsoft.Common.targets (or Microsoft.CSharp.targets) for the built-in PostBuildEvent. Notice how it guards on both the RunPostBuildEvent setting and whether any outputs were actually produced (@(TargetOutputs)):
<!--
In Microsoft.Common.targets (or CSharp targets),
the PostBuildEvent target looks something like this:
-->
<Target
Name="PostBuildEvent"
AfterTargets="Build"
Condition="
'$(RunPostBuildEvent)' != 'Never'
AND
(
'$(RunPostBuildEvent)' == 'Always'
OR
(
'$(RunPostBuildEvent)' == 'OnOutputUpdated'
AND
'@(TargetOutputs)' != '' <!-- ← only if something really built -->
)
)
">
<Exec Command="$(PostBuildEvent)" />
</Target>
Breakdown of the Condition:
$(RunPostBuildEvent) != 'Never'
– you haven’t disabled post‐builds entirely.
- Either
• $(RunPostBuildEvent) == 'Always'
– run it every time, or
• $(RunPostBuildEvent) == 'OnOutputUpdated' AND '@(TargetOutputs)' != ''
– only if MSBuild actually produced outputs (i.e. a real compile happened).
If you set
<PropertyGroup>
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
</PropertyGroup>
that reproduces VS’s “Run only if the build updated my DLL/EXE” behavior.