The obvious solution seems to code a script (bat, shell, powershell, python...) that will do exactly what you want; I don't think there's any built-in functionality to do what you need. I believe build files simply run the executable they're pointed to and output to the console. Point the build system to your script and its output would be visible there too.

Because you can pass the $ProjectDir location to your script, you can inspect the project file for the information you need and use it to exclude files, etc.