Skip to content

Latest commit

 

History

History
54 lines (34 loc) · 2.82 KB

File metadata and controls

54 lines (34 loc) · 2.82 KB
title Specify custom build events
description Explore how you can you can automatically run commands in Visual Studio before you start a build of your project or solution or after a build completes.
ms.date 10/2/2025
ms.subservice compile-build
ms.topic concept-article
helpviewer_keywords
build events, customizing
author ghogen
ms.author ghogen

Specify custom build events in Visual Studio

Visual Studio lets you specify custom build commands to run automatically before a build starts or after it finishes. You might create commands to run a .bat file before a build starts or copy new files to a folder after the build completes. Custom build events run only when the build successfully reaches the relevant point in the build process.

This article gives an overview of the recommended syntax for custom build commands. If you're looking for information about a specific programming language, see Visual Basic, C# and F#, and Visual C++.

Tip

If you want to add complex operations to your build process, explore the MSBuild customization techniques. For example, you can add build events to generate code files, and properly handle the clean up after a clean operation or only run the task when the inputs are out of date.

Syntax for custom build commands

Build commands follow the same syntax as Windows command prompt commands and you can use MSBuild properties (also known as macros) to easily create the events. For a list of available MSBuild properties, see Common MSBuild project properties. You can also define your own MSBuild properties in the project file.

For best results, follow these formatting tips:

  • Add a call statement before all build events that run .bat files.

    Example: call C:\MyFile.bat

    Example: call C:\MyFile.bat call C:\MyFile2.bat

  • Enclose file paths in quotation marks.

    Example: "%ProgramFiles(x86)%\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.8 Tools\gacutil.exe" -if "$(TargetPath)"

  • Separate multiple commands by using line breaks.

  • Include wildcards as needed.

    Example: for %I in (*.txt *.doc *.html) do copy %I c:\<Directory>\

    [!NOTE] For a batch script, replace the variable %I in this example with %%I.

Related content