Visual Studio Macros and Build Events

Visual Studio has a nifty feature called Post/Pre Build events. These are used to include extra Dos commands and Macros and execute them before or after the build.

You can open it using project properties, and it will open a dialog as shown below:

Build event dialog

For post-build events, you can define when to run commands included as shown in the below snap:

post build events

You can click the respective Edit build buttons, and it will open a popup as shown below:

visual studio build popup

By clicking the Macro button, it will open the macro listing and its respective value.

Using Macros and Dos command, you can copy files from one location to another and run batch files. In my current project, I do have the below command to copy XML files and email templates from the common code project to my solution directory:

RD "$(SolutionDir)WebAdmin\XML"
MD "$(SolutionDir)WebAdmin\XML"
COPY "$(ProjectDir)XML" "$(SolutionDir)WebAdmin\XML"

RD "$(SolutionDir)WebAdmin\EmailTemplates"
MD "$(SolutionDir)WebAdmin\EmailTemplates"
COPY "$(ProjectDir)EmailTemplates" "$(SolutionDir)WebAdmin\EmailTemplates"

In the above code, $(SolutionDir) and $(ProjectDir) are macro names. Macros are non-case-sensitive. Check out this link that shows macros along with their descriptions.

Use this nifty feature and automate your tasks.





Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: