Saturday, May 8, 2010

VC++ 2008 Setting up projects with Common properties

As detailed in the MSDN documentation. It is possible to access some of the common paths the VStudio environment provides using symbolic names($(ConfigurationName), $(SolutionDir) etc.). Nevertheless, sometimes it is needed the access for a more specific paths, and create more symbolic names defined by the user. This can be done creating User Macros.
The purpose of this set up, is to provide a way to re-use the configuration among several projects of the solution. I'm currently working on C++ projects, although it makes sense to use this information for C# or VisualBasic projects.

Lets move to the VStudio enviroment.

1. Create a special project to control the build order or dependencies. In this case we will take advantage on this project to create a User Macro and inherit its properties to other projects. Open its Property Page->Configuration Properties->Configuration Type set it to Utility.

2. Open the Property Manager (View->Property Manager). Select the correct Configuration Name for the special project(Debug, Release or whatever), right click the folder Configuration Name and "Add New Project Property Sheet ...", select the Property Sheet Template and set a name, "CommonProperties". Right click the CommonProperties sheet and open its Properties. Select "User Macros", the list should be empty by now, select AddMacro.

Close and open the properties and you will notice the Evaluated value field has been refreshed, possible to verify the result of the provided path for the bin output.

3. Back in the Property Manager view, rick click on each project using the appropriate Configuration Name, and select "Add existing property sheet...". Select the Solution explorer view and rick click one of the project which set a existing property sheet. You should notice the field "Inherited Project Property Sheets" points to the correct Property Sheet.

If this common property is edited and changed it will affect each of the projects inheriting. To test you can compile several of you projects and verify all of them have the same binary output as the one provided by the special project.

No comments:

Post a Comment