Question

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.

Was it helpful?

Solution

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.

  1. Load your solution file with your .exe and .lib projects. Let's suppose the name of your library is PowerMath.lib and your main executable is SuperCalc.exe.
  2. Find the Solution Explorer window in Visual Studio. This is the sub-window that lists all your projects, and the files inside those projects. (If you don't have one, click on the View menu and choose the Solution Explorer option to create one.)
  3. First, let's take the settings out of the Project Properties where you have them set now. Go to the project properties for the 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).
  4. Down at the bottom of the Solution Explorer window you will see several tabs, including: Solution Explorer, Class View, and Property Manager. These may be abbreviated if the window is small. Click on Property Manager.
  5. In the Property Manager you'll see two entries: the PowerMath and SuperCalc project names. Right-click on the PowerMath.lib project, and choose the menu option Add New Property Sheet.
  6. Choose a good Name that refers to your library. I would suggest PowerMath-settings.props. Then click Add to create the property sheet, and automatically attach it to the PowerMath .lib project.
  7. Back in the Property Manager pane, you see that PowerMath has two elements underneath it: Debug and Release. These are the two configurations of your library. If you "open them up" by clicking on them with the mouse, you'll see that the PowerMath-settings property sheet has been attached to both configurations.
  8. The 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.
  9. Double-click on the 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.
  10. Now you get to write your additional library dependencies and additional include directories. Go to the dialog boxes where you expect to set those things. In the appropriate fields, click the little down arrow at the right side of the field and pick Edit....
  11. In the edit box you will see a blank space where you can write your new settings. (You'll also see the "inherited values", which are the settings that came from other property sheets.) Add your stuff and then click OK.
  12. When you're done, you'll have a property sheet called PowerMath-settings.props that stores the settings needed for all users of the PowerMath.lib library.
  13. Now go back to the Property Manager window. Right-click on the SuperCalc project instead (this is your .exe). Choose the menu option Add Existing Property Sheet. Find PowerMath-settings.props and select it.
  14. Boom, now SuperCalc.exe gets all the settings you just created for PowerMath.lib.
  15. To verify this, switch back from Property Manager to Solution Explorer (by clicking the Solution Explorer tab along the bottom of the sub-window). Go to Project Properties for your 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".
  16. Sometimes the settings for a brand-new property sheet are not applied until you quit Visual Studio, re-start, and re-load the solution. Remember to click YES when it asks whether you want to save your project changes and new property sheets! Once it's all set up you shouldn't need to do this again.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top