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:
For post-build events, you can define when to run commands included as shown in the below snap:
You can click the respective Edit build buttons, and it will open a popup as shown below:
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