It is possible to execute pre and post build steps for C# and VB.NET projects by utilizing a special project type from C++ called a utility project. Prior to testing a server application you must install it into the GAC and register it using regsvcs running on an account with administrative privileges. You can create scripts that will automate this process by doing the following:
- Add a new project to your solution
- Select the project type Visual C++ projects
- Select the template Makefile Project
- Enter the name Pre-Build
- Click OK - this will display the makefile project wizard
- Click finish on the makefile project wizard
- Right click on the Pre-Build project and select properties
- In the General page of the configuration properties, change the configuration type to Utility
- Click the apply button - new options will appear when you do this
- Select the build events folder and Pre-Build Event
- In the Command Line enter Pre-Build.bat along with any parameters you require for your build script.
- Repeat steps 1-11 for Post-Build events (substitute Post-Build wherever it says Pre-Build)
- Select Project / Project Dependencies... from the menu
- All projects should depend on Pre-Build, this will cause it to build first
- Post-Build should depend on all the other projects, this will cause it to build last.
Now you can create the two build scripts Pre-Build.bat and Post-Build.bat with the commands that you want to run when these events occur.
Pre-Build In the pre-build event, you should return the machine to a known state so you will want to remove the assembly from the GAC and uninstall the Enterprise Services application if the assembly exists. Be aware that regsvcs.exe returns an error if the assembly does not exist which Visual Studio will interpret as a build error.
Post-Build In the post build event, you will want to take the steps necessary to deploy and register the server app in preparation for debugging. For most Enterprise Services assemblies this includes adding it to the GAC and calling regsvcs.exe to register the assembly. |