After Publish event in Visual Studio

UPDATE: seems like in VS 2019 and .NET 5 you can now use Publish target.

<Target Name="Test" AfterTargets="Publish">
    <Exec Command="blablabla" />
</Target>

Here’s my old answer that also works:


MS has confirmed, that when publishing to file system they don’t have any target to launch after that.

“We currently do not support executing custom targets after publish
from VS for the file system protocol.”

Quoted from this SO question

So what we ended up doing is:

  1. use AfterTargets="CopyAllFilesToSingleFolderForPackage" (runs just before the files are copied to the publish location)
  2. which executes a bat-file
  3. the bat-file starts with a timeout 10 command (waits 10 seconds) – for the lack of a better way.

IMPORTANT: This bat file has to be executed asynchronously so the publish process continues after it’s been launched, please refer to this SO answer on how to do that.

Leave a Comment