Visual Studio has a handy feature to run commands before or after builds. This can be used to automate some of your development processes, such as fetching dependencies during the pre-build phase or sending build artifacts to development environments.

Configure pre-build and post-build commands

From Visual Studio, right click on the project and click “Properties”.

    Visual Studio, right-click the project, click "Properties."

Then under “Build Events” you will find the commands to define the commands that run before and after build. This is a default CMD prompt, so if you want to run Powershell or Bash commands, you will need to launch Powershell or WSL respectively and pass it in a script.

Note that this command is run in the build artifacts directory. This may vary depending on your setup, but it is usually project/bin/ProfileName/. You will need to add relative references to run commands in higher subdirectories.

Execution of pre-construction and post-construction events.

At the bottom you can set some controls for the post-build command. If you don’t want to do anything with a failed build, set it to “On Successful Build” and if you don’t want to send duplicate builds, set it to “When build updates”.

If you click on “Edit post-build”, you will see a window listing all the variables you can pass to your script.

 "Edit post-construction" variables.


Please enter your comment!
Please enter your name here