Visual Studio.

Visual Studio has a handy feature for running commands before or after builds. This can be used to automate some of your development process, such as pulling in dependencies during the prebuild phase, or sending build artifacts to development environments.

Setting Up Prebuild and Post-build Commands

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

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

Note that this command is executed in the directory of the build artifacts. This can vary depending on your configuration, but it’s generally project/bin/ProfileName/. You’ll need to add relative references to run commands at higher subdirectories.

Running prebuild and postbuild 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 this to “On Successful Build,” and if you don’t want to send duplicate builds, set this to “When the build updates.”

If you click “Edit Post-Build,” you’ll see a window listing all the variables you can pass to your script.

 "Edit Post-Build" variables.

Profile Photo for Anthony Heddings Anthony Heddings
Anthony Heddings is the resident cloud engineer for LifeSavvy Media, a technical writer, programmer, and an expert at Amazon's AWS platform. He's written hundreds of articles for How-To Geek and CloudSavvy IT that have been read millions of times.
Read Full Bio »