Sunday, April 14, 2013

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 build.

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

BuildEvent Dialog

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

Post-build events

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

Build Popup

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

By using Macros and dos command you can copy files from one location to another and run batch files and so on. In my current project I do have below command to copy xml file and email templates from 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 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 Smile

No comments: