
The best way to debug msbuild, or to find what targets and tasks are triggered, and where can you hook up, is to ask msbuild to be more verbose (under VS tools->options).

After looking at what targets are executed when publishing application from within VS by using
Local Environment as a publish method, one can see that
BeforePublish and
AfterPublish was never triggered. But you can start using any target that you can see in log to do desired operation. For example, if I want to do something after
CompileWebSite target is finished running I just write something like:
<Target Name="CopyToDeployFolder" DependsOnTargets="CompileWebSite">
<Exec Command="xcopy.exe $(OutputDirectory) $(DeploymentDirectory) /e" WorkingDirectory="C:\Windows\" />
</Target>
Namedoesn't matter, it is
DependsOnTargets that is important.