I don't know much about MSBuild, but in the case of the MSBuild projects used by Visual Studio for C# there is a simple-minded alternative: Use a Post-build build event instead of an AfterBuild target.
You can set up a Post-build build event via the Visual Studio project properties dialog, on the third tab "Build Events". For some situations it may be an idea to enter some commands on this dialog, and then edit the .csproj file directly once you've determined how it works.
Remember to select "Run this post-build event: When the build updates the project output" on the dialog - that's the key to getting the functionality requested by the OP.
Like I say, I don't know much about MSBuild, and it may be that the Post-build build event is not applicable for some things that the AfterBuild target can do. But I've used it for copying files and running BAT scripts, and for that it works fine.
EDIT:
I'll add a few notes about how I usually use post-build events in my C# projects.
In order to separate different areas of functionality I usually create a BAT script called PostBuildEvent.bat, and place it in the same folder as the .csproj file. Then my post-build event contains only two lines:
cd $(ProjectDir)
PostBuildEvent.bat
Then I place the commands I want in the PostBuildEvent.bat file. Here's an example:
copy "..\..\..\..\..\Shared Bin\Merlinia.CommonClasses.NamedPipesNative.dll" bin
copy "..\..\..\..\..\Shared Bin\Merlinia.CommonClasses.NamedPipesNative.pdb" bin
cd Packed-NonObfuscated
call PackForWindowsSystem32-NonObfuscated.bat
cd ..\
cd Packed-Obfuscated
call PackForWindowsSystem32-Obfuscated.bat
cd ..\
pause
Remember that to call a BAT script from a BAT script you explicitly specify "call". Note also the use of "pause" - this makes it possible to test the script by double-clicking on the BAT file and then you can see any error messages in the cmd window. The "pause" is ignored when the script is run via MSBuild.