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:
![BuildEvent Dialog Build event dialog](https://i0.wp.com/nileshthakkar.com/wp-content/uploads/2023/05/53d3a-buildevent252520dialog_thumb25255b225255d.png?resize=503%2C375)
For post-build events, you can define when to run commands included as shown in the below snap:
![Post-build events post build events](https://i0.wp.com/nileshthakkar.com/wp-content/uploads/2023/05/0b6d2-post-build252520events_thumb25255b325255d.png?resize=386%2C107)
You can click the respective Edit build buttons, and it will open a popup as shown below:
![Build Popup visual studio build popup](https://i0.wp.com/nileshthakkar.com/wp-content/uploads/2023/05/9117d-build252520popup_thumb25255b125255d.png?resize=427%2C293)
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