I am having a problem with Visual Studio 2012, and I am hoping there is a solution to this. I have in my solution 2 projects: 1 project is an ".exe" project, and the other is a ".lib" project. I have added the lib project as a reference in the exe project, and I have ensured that it is scheduled to be compiled first. The lib project has a bunch of additional include directories and a bunch of additional dependencies and linked libraries. The lib project compiles fine. However, none of the additional include directories or additional library directories or dependencies are being inherited by the exe application. I was able to resolve this by copying the configurations to the exe project, but that means that if I ever update the lib dependencies, then I need to update it in every project that uses this library (I play to use this library for multiple projects). This seems like something that there should be a solution for, but I just can't seem to find it. Has anyone figured out a way to have projects inherit the configurations of referenced projects, or is there no way around this? Thanks.
You're right, projects don't inherit the properties of other projects they reference. To solve your problem what you need is a property sheet. A property sheet is a collection of Properties (like you set in your Project Properties) separate from a project. You can apply a single property sheet to many projects.
In your case, the "additional library dependencies" and "additional include directories" will be placed into a property sheet. That property sheet will be applied to both your .exe
project and your .lib
project. When you make changes, you will make them to the property sheet and both projects will see the changes.
Let's go step-by-step through setting up a property sheet to do what you want.
.exe
and .lib
projects. Let's suppose the name of your library is PowerMath.lib
and your main executable is SuperCalc.exe
.PowerMath.lib
project (right-click on that project in the Solution Explorer and choose Properties from the context menu). Find your "additional library dependencies" and "additional include directories" settings that you made, and delete them. (Only delete your changes, not whatever was there before.) (Also, write your stuff down or copy it somewhere -- it's going to come back in step 10.) When you are done with the PowerMath.lib
project, repeat the process with the SuperCalc.exe
project. Rip it all out so it doesn't interfere with the new approach we're going to take. Be sure you've done this for all configurations of your projects (Debug and Release, Win32 and x64).PowerMath
and SuperCalc
project names. Right-click on the PowerMath.lib
project, and choose the menu option Add New Property Sheet.PowerMath-settings.props
. Then click Add to create the property sheet, and automatically attach it to the PowerMath
.lib project.PowerMath-settings
property sheet has been attached to both configurations.PowerMath-settings
property sheet is listed above a bunch of other property sheets that were already present, which have names like Core Windows Libraries
and Unicode Support
. All of the settings in any configuration of your projects come from combining these property sheets! That's how properties work inside Visual Studio -- putting together all the project's property sheets, in order with the first one at the bottom.PowerMath-settings
property sheet in the list. This will take you to the familiar Project Properties interface. Changes made here don't apply to a project or a particular configuration inside that project. Instead, you're writing the settings only for the property sheet PowerMath-settings.props
.Edit...
.PowerMath-settings.props
that stores the settings needed for all users of the PowerMath.lib
library.SuperCalc
project instead (this is your .exe). Choose the menu option Add Existing Property Sheet. Find PowerMath-settings.props
and select it.SuperCalc.exe
gets all the settings you just created for PowerMath.lib
.SuperCalc.exe
project. Go to "additional include directories". Click on the down-arrow at the left side of that field and pick Edit...
. You will see that your property sheet settings are listed as "inherited values".Now any time you have a new project that uses PowerMath.lib
, just go to the Property Manager and Add Existing Property Sheet: PowerMath-settings.props
.
Remember that all changes made to the properties in the property sheet have to be made via the Property Manager dialog boxes, not using the PowerMath.lib
Project Properties! Project Properties is a kind of "override" property sheet that only applies to one specific project. It stands above all the property sheets listed by the Property Manager.