How to: Specify a Pre-build or Post-build Command Line

If you must perform actions before or after the database project is built and deployed, you can perform them by specifying a pre-build or post-build command line. You specify these command lines by using the project properties. As examples, you might use a pre-build or post-build command line in the following scenarios:

(Pre-build) To copy a .sql file from a SQLCLR project into the schema objects so that your database project and the SQLCLR project are synchronized.

To specify a pre-build command line

In Solution Explorer, right-click the database project for which you want to specify a pre-build command line, and click Properties.

In the Project Properties window, click the Build Events tab.

Do one of the following:

If you know the command line that you want to execute, in Pre-build event command line, type the command line that you want to execute before the database project is built, and then go to step 5.

If you want to use build macros, click Edit Pre-build. In the Pre-build Event Command Line dialog box, type the command line that you want to execute. You can click a macro in the list and click Insert to insert the macro into your command line.

When you have finished editing the command line, click OK.

On the File menu, click Save Selected Items to save the changes that you made to the project properties.

The next time that you build the database project, the command line is executed before the database project is built.

To specify a post-build command line

In Solution Explorer, right-click the database project for which you want to specify a post-build command line, and click Properties.

In the Project Properties window, click the Build Events tab.

Do one of the following:

If you know the command line that you want to execute, in Post-build event command line, type the command line that you want to execute after the database project is built, and then go to step 5.

If you want to use build macros, click Edit Post-build. In the Post-build Event Command Line dialog box, type the command line that you want to execute. You can click a macro in the list and click Insert to insert the macro into your command line.

When you have finished editing the command line, click OK.

If you want to run the command line only if the build was successful, in the Run the post-build event list, click On successful build. If you always want the command line to run even if the build fails, in the Run the post-build event list, click Always.

On the File menu, click Save Selected Items to save the changes that you made to the project properties.

The next time that you build the database project, the command line is executed after the database project is built.