In order to be able to reuse segments of code through multiple application, I have decided to create Static Libraries of the functions/classes I often require. Consequently, I can change the code of a static library and all the applications referencing that library have updated functions.
The Architecture conceptually looks like the following graph :
AppA -> LibA
\
-> LibCommon -> LibX
/ -> LibY
AppB
Each applications (AppA, AppB) reside in different solutions to keep stuff clearly separated.
In order to get that fully working in Visual Studio 2010, I have to add the project of each Lib used by the application in it's solution, add the folder containing it's header files in the Additional Include Directories
and add a reference to the project directly used.
Ex. For AppA, I would;
Additional Include Directories
propertyMy first question is : Is there a way to only import the library the application directly requires? (LibA and LibCommon)
My second question : Is there a better way to easily manage reusable code in Visual Studio 2010? (Junior Programmer Here!)
You don't really need to include the projects of those libs. You only need the .h files for the compiler, and the .lib files for the linker. What I would do is first organize the libs projects at some fixed directory structure. Then, I'd add something along these lines to LibCommon.h:
#include "LibXDir/LibX.h"
#include "LibYDir/LibY.h"
#ifdef _DEBUG
#pragma comment (lib, "LibCommon.lib")
#pragma comment (lib, "LibXDir/Debug/LibX.lib")
#pragma comment (lib, "LibXDir/Debug/LibY.lib")
#else
#pragma comment (lib, "LibCommon.lib")
#pragma comment (lib, "LibXDir/Release/LibX.lib")
#pragma comment (lib, "LibXDir/Release/LibY.lib")
#endif
With this, you'd only have to include LibCommon.h in your apps, and it will take care of bringing in the rest of the libs. You might have to set up the additional include and library directories, depending on your setup. Alternatively, you can have all the .lib files created or copied to some central lib directory, which could then be the only lib directory you have to add.
I'm assuming you're not going to modify the libs while working on the apps. If you are, you'll have to recreated the libs after they are changed, and that could be done by indeed adding their projects to the solution. But you can still have most of the dependencies set up on a single file, rather than on the project settings.