Need to set a comman library file for all projects of a single solution Visual studio 2010 - c++

I need some help to add a .*lib file for my solution and this solution has many projects.
I am going to make it more clear. Lets i have a "ABC.sln" solution in visual studio 2010. This ABC.sln has several projects (VC++ Project (1,2,3....*vcxproj) and these 1, 2 and 3 projects required a 123comman.lib file in the linker option of their respective projects.
Currently i add this library file in all three projects and it works fine but i think there must be some way to set this library file as a common stuff for all projects inside a solution. So that i just set it once and all projects can share it.
Is it possible ? if yes how can we do that ?
Thanks!

VS2010 introduced the concept of Property Pages, which is distinct and separate from Project Settings. Property Pages are similar to Project Settings in that you can specify things like additional dependencies, language rules, optimization settings, etc. But unlike Project Settings, Property Pages use a different file to store these settings, and these files can be shared across all (or any) projects in your solution.
Documentation for Property Pages is here -- I'll leave the details up to you. But to get started, go to View > Property Manager, open up one of your projects, create a new property page for a given platform (x64 Debug, x64 Release, etc), and set your settings. Then you can use this Property Page in your other projects.

Projects can share configuration via property sheets. You can create them in the project configuration tree by right-clicking a project and selecting "add property sheet" or something like that (been a while). In a property sheet, you can specify the import, and then you can add the property sheet to all other projects as well.
This does not reduce the initial work: you still have to add something to every project. Solutions do not have the ability to inject anything into projects; they're a completely different file format.
However, it does save you work if you then have to do another task that is common to all projects, like changing the library name you want to include, or adding another library. Then you only have to do it once, in the property sheet.

Make a NuGet package out of this library, and use the package manager to add the dll to all projects.
An in-depth description of how to generate a NuGet package for C++ code can be found here.
If you do it this way, it only takes a single click per project (to enable the checkbox when adding the package in package manager) to add the library as dependency.

If your problem is only about sharing the same file among different projects in a single solution. You can add the file at solution level and then do add existing items in individual projects and choose to add them as link.
This way you have only one copy of file that is shared.

Related

Libraries VS2015

Good evening
I'm trying to set up a development environment on my newly Boot-Camped Windows 10.
I know how to link the include/lib in VS. On my Mac all my external libraries and include files are at either:
/use/local/ or /opt/local/
I'm wondering whether there is an easy way to do this on windows, or are there a way to force VS to always look in a particular dir?
Cheers
VS has the concept of property sheets which basically are a predefined set of properties for your project. Every C++ project includes by default few property sheets and there's even a special property sheet called Microsoft.Cpp.[Platform].user where [Platform] is either Win32 or x64. By editing the contents of this file you can set the paths for all your projects (or other arbitrary values such as macros).
To edit these files do either of the following:
Make a new CPP project in VS. Go to View->Other Windows->Property Manager. This will show a new pane in the current window and from there you can find the property sheet and edit as you see fit. This approach has the benefit of being more user-friendly as VS provides some nice GUI. Here's one tutorial
Find the files themselves (they are located in %LOCALAPPDATA%\Microsoft\MSBuild\v4.0), open them using your favourite text editor and do your magic. The files are XML-based so it's not awfully difficult.

How to automate changing the project settings in Visual Studio 2005 and later

i have a visual studio 2005/2010 projects and each of these project is made up of 20 projects and all these projects are managed by a single solution file(.sln)
now if i had to change any compiler or linker settings, i have to manually do it for all the 20 projects, is there anyway this can be automated using a script or Addin or any other method.
appreciate your time and attention
What you are looking for are property sheets. Visual Studio already has a mechanism that almost enables you to do everything you are asking for.
A property sheet (*.props) basically is a separate settings file that you can attach to as much projects that you like, and all the configured properties are applied to these projects. Think of it as if the projects are "inheriting" from another configuration - and that's exactly what's happening.
Let's say you have a base configuration of include directories, linker directories, library includes, preprocessor defines and so forth, and you know that each project uses them in each configuration (Debug, Release, ...). You can create one property sheet defaults.props and apply it to all your 20 projects. Then, if you require a change, just edit the property sheet file, and all the changes will be reflected to all 20 projects.
To create property sheets, click on View -> Property Manager (not to be confused with the "Property Window"!). A window should pop up where you can see all your projects with all their configurations. Now right click on any of your projects and select Add New Property Sheet, type in a name and save it somewhere. This will create a .props file and adds it to all the configurations of your single project. You can then edit this property sheet from this window like it was a real project (right click on the property sheet and select Properties).
After you have created your property sheet you can go ahead and right click on the other 19 projects and do a Add Existing Property Sheet. You have to do this once for all your projects, sure, but after that your property sheet enables you to change the settings for all projects at once.
Also noteworthy is that you can have multiple property sheets applied to one project. If you do so, they are being applied in order (you can reorder them if you like) so you are able to configure your projects in more detail. For instance, you could have this default.props that applies to everything, and then you could have a default_debug.props that is only intended for Debug configurations. The first one sets up all your include and library directories, the second one does library specifications and defines specific for Debug configs.
One last important note: If you have set some properties directly in your project (which you obviously have), it will automatically override any settings you have specified in your property sheet. You can see this if a setting in your project has a bold value. If you want to revert it to the property sheet value, clear the setting and select the <inherit from parent or project defaults> from the drop down menu of the setting. Include- and Linker-Directories are a special case, in which you will ALWAYS inherit everything specified in the property sheet unless explicitly disabled.
EDIT: I am not quite sure about VS2005/VS2008, and iirc they have the same principle with a *.vsprops file, but this may be incompatible with the *.props files from VS2010+

Import Existing C++ Source Code into Visual Studio

I am trying to import an existing c++ application's source into visual studio to take advantage of some specific MS tools. However, after searching online and playing with visual studio, I cannot seem to find an easy way to import existing c++ source code into visual studio and keep it structurally intact.
The import capacity I did find flattens out the directories and puts them all into one project. Am I missing something?
(This is all unmanaged C++, and contains specific builds for win/unix)
With no project/solution loaded, in Visual Studio 2005 I see this menu item:
File > New Project From Existing Code...
After following the wizard, my problem is solved!
Switching the "Show All Files" button shows the complete hierarchy with all directories and files within.
If the New Project From Existing Code... option isn't available, you'll need to add it in Tools > Customize...
I am not aware of any general solution under the constraints given - specifically having to create many projects from a source tree.
The best option I see is actually creating the project files by some script.
Creating a single project manually (create empty project, then add the files),
Configure it as close as possible as desired (i.e. with precompiled headers, build configurations, etc.)
Use the .vcproj created as skeleton for the project files to be created
A very simple method would file list, project name etc. with "strange tokens", and fill them in with your generator. If you want to be the good guy, you can of course use some XML handling library.
Our experience: We actually don't store the .vcproj and .sln in the repository (git) anymore, but a python script that re-genrates them from the source tree, together with VS 2008 "property sheet templates" (or whatever they are called). This helps a lot making general adjustments.
The project generation script contains information about all the projects specialties (e.g. do they use MFC/ATL, will it create DLL or an EXE, files to exclude).
In addition, this script also contains dependencies, which feeds the actual build script.
This works quite well, the problems are minor: python requried in build systems, not forgetting to re-gen the project files, me having to learn some python to make adjustments to some projects.
#Michael Burr "How complex are the python scripts and whatever supporting 'templates' you might need?"
I honestly can't tell, since I gave the task to another dev (who picked python). The original task was to provide a build script, as the VS2008 solution build was not good enough for our needs, and the old batch file didn't support parallelization. .vcproj generation was added later. As I understand his script generates the .vcproj and .sln files from scratch, but pulls in all the settings from separate property sheets.
Pros:
Adding new configurations on the fly. Some of the projects already had six configurations, and planning for unicode support meant considering doubling them for a while. Some awkward tools still build as MBCS, so some libs do have 8 configs now. Configuring that from hand is a pain, now it just doesn't bother me anymore.
Global changes, e.g. moving around relative project paths, the folder for temp files and for final binaries until we found a solution we were happy with
Build Stability. Merging VC6 project files was a notable source of errors for various reasons, and VC9 project files didn't look better. Now things seem isolated better: compile/link settings in the property sheets, file handling in the script. Also, the script mostly lists variations from our default, ending up easier to read than a project file.
Generally: I don't see a big benefit when your projects are already set up, they are rather stable, and you don't have real issues. However, when moving into the unknown (for us: mostly VC6 -> VC9 and Unicode builds), the flexibility reduced the risk of experiments greatly.
Create a new empty solution and add your source code to it.
For example,
File>New>Project...
Visual C++>Win32>Win32 Console Application
Application Settings>
- Uncheck "Precompiled Header"
- Check "Empty Project"
Project is then created. To add existing code:
Project>Add Existing Item...>
- Select file(s) to add
Recompile, done!
In the "Solution Explorer" you can click on the "Show All Files" button to have Visual Studio display the files as they exist on the file system (directories and all).
In my opinion this is an imperfect workaround, but I believe it's the best available. I'm unaware of a plug-in, macro or other tool that'll import a directory into an actual project with folders that mirror the file system's.
I know this question is already marked correct, but I was able to import existing code into a project with Visual Studio 2008 by doing "File" -> "New Project from existing code". The directory structure of my code was retained.
You can always switch view from project menu
For eg. Project->Show All Files
The above will display the files in unformated raw file system order
Not sure of older versions but it works on VS 2010
I understand you, I have the same problem: many .cpp and .h files organized in many folders and subfolders with include paths written for this folder structure. The only way you can do to import this folder structure together with the source files is to use "Show All Files" and then right-click on folders and select "Import in Project". This works for me when I am using C-Sharp projects. But it does not work for my C++ Projects. I am still searching for a solution...

visual C++ express 2010 and setting env variables solution wide

I'm C++ dev migrating to visual 2010 c++ from vim/g++. Here blog I've read that VC++ directories are no more and that I should use property pages in vs 2010 but I don't know how... Here is what I need to do. I have w solution (50 projects strong) and all of them use boost, pthreads, xercesc and few other libs. I have env variables that point to those libs on my hard drive. How can I tell VS to use them as additional include paths? Again, it's 2010 version so no vs per solution setup available. I do not want to set it manually in every project.
The answer to your question is also in the blog that you linked to, but it's mentined in a kind of round about way:
If you open up the Property Manager view to see the property sheets associated with your project, you’ll see that one of the property sheets is named Microsoft.Cpp.Win32.User. This property sheet is actually stored in LocalAppData, just as VCComponents.dat file was, in the directory %LocalAppData%\Microsoft\VisualStudio\10.0. Using the property editor on the property sheet (just right-click on this property sheet node and select Properties…), you can see that you are able to make edits directly to this file. Since all projects, by default, import this property sheet, you are effectively editing the VC++ directories in the same way you were able to do before.
The key is that you get to the VC++ Directories property through the "Property Manager" windows (open it via the View/"Property Manager" menu selection). The VC++ Directories setting is in the "Microsoft.Cpp.Win32.user" property sheet - that edits the global setting, so you should only have to do it once.
There seem to be quite a few people who dislike this change; I think that's because it's less discoverable and obvious than how the setting was managed before. The trade-off is that it's more flexible and integrates into the MSBuild architecture better, and once you do know about it it's just as easy to change as before (it's just harder to find, particularly if you're used to the old place).
View->Property Manager
Select all projects
Add one, new, common property page for all projects
"Microsoft.Cpp.Win32.user" - (as name say) better use for some user specific settings (or better do not use at all)
Mariusz

Building both DLL and static libs from the same project

I have a number of native C++ libraries (Win32, without MFC) compiling under Visual Studio 2005, and used in a number of solutions.
I'd like to be able to choose to compile and link them as either static libraries or DLLs, depending on the needs of the particular solution in which I'm using them.
What's the best way to do this? I've considered these approaches:
1. Multiple project files
Example: "foo_static.vcproj" vs "foo_dll.vcproj"
Pro: easy to generate for new libraries, not too much manual vcproj munging.
Con: settings, file lists, etc. in two places get out of sync too easily.
2. Single project file, multiple configurations
Example: "Debug | Win32" vs "Debug DLL | Win32", etc.
Pro: file lists are easier to keep in sync; compilation options are somewhat easier to keep in sync
Con: I build for both Win32 and Smart Device targets, so I already have multiple configurations; I don't want to make my combinatorial explosion worse ("Static library for FooPhone | WinMobile 6", "Dynamic library for FooPhone | WinMobile 6", "Static library for BarPda | WinMobile 6", etc.
Worse Con: VS 2005 has a bad habit of assuming that if you have a configuration defined for platform "Foo", then you really need it for all other platforms in your solution, and haphazardly inserts all permutations of configuration/platform configurations all over the affected vcproj files, whether valid or not. (Bug filed with MS; closed as WONTFIX.)
3. Single project file, selecting static or dynamic via vsprops files
Example: store the appropriate vcproj fragments in property sheet files, then apply the "FooApp Static Library" property sheet to config/platform combinations when you want static libs, and apply the "FooApp DLL" property sheet when you want DLLs.
Pros: This is what I really want to do!
Cons: It doesn't seem possible. It seems that the .vcproj attribute that switches between static and dynamic libraries (the ConfigurationType attribute of the Configuration element) isn't overrideable by the .vsprops file. Microsoft's published schema for these files lists only <Tool> and <UserMacro> elements.
EDIT: In case someone suggests it, I've also tried a more "clever" version of #3, in which I define a .vsprops containing a UserMacro called "ModuleConfigurationType" with a value of either "2" (DLL) or "4" (static library), and changed the configuration in the .vcproj to have ConfigurationType="$(ModuleConfigurationType)". Visual Studio silently and without warning removes the attribute and replaces it with ConfigurationType="1". So helpful!
Am I missing a better solution?
I may have missed something, but why can't you define the DLL project with no files, and just have it link the lib created by the other project?
And, with respect to settings, you can factor them out in vsprop files...
There is an easy way to create both static and dll lib versions in one project.
Create your dll project. Then do the following to it:
Simply create an nmake makefile or .bat file that runs the lib tool.
Basically, this is just this:
lib /NOLOGO /OUT:<your_lib_pathname> #<<
<list_all_of_your_obj_paths_here>
<<
Then, in your project, add a Post Build Event where the command just runs the .bat file (or nmake or perl). Then, you will always get both a dll and a static lib.
I'll refrain from denigrating visual studio for not allowing the tool for this to exist in a project just before Linker (in the tool flow).
I think the typical way this is done is choice 2 above. It is what I use and what I have seen done by a number of libraries and companies.
If you find it does not work for you then by all means use something else.
Good luck.
I prefer 2 configurations way.
Setup all common settings via 'All configurations' item in a project properties windows. After it separated settings. And it's done. Let's go coding.
Also there is very good feature named 'Batch build', which builds specified configurations by turn.
Multiple projects are the best way to go - this is the configuration i have most widely seen in umpteen no of projects that i have come across.
That said, it might be also possible to implement the third option by modifying your vcproj files on the fly from external tools(like a custom vbscript), that you could invoke from a make file. You can use shell variables to control the behavior of the tool.
Note that you should still use use visual studio to make the build, the makefile should only launch your external tool if required to make the mods and then follow that by the actual build command
I use Visual Studio 6.0 (Still) due to issues that are preventing us from Migrating to VS2005 or newer. Rebuilding causes severe issues (everything breaks)... so many of us are considering lobbying a migration to GnuC++ moving forward in a structured way to eventually get us off of licensed Visual Studio products and onto Eclipse and Linux.
In Unix/Linux it is easy to build for all configurations.. so I can't believe what a time and productivity sink it is to try and accomplish the same task in Visual Studio. For VS6.0 I have so far found that only having two separate projects seems to be workable. I haven't yet tried the multiple configuration technique, but will see if it works in the older VS6.0.
Why not go for version 1 and generate the second set of project files from the first using a script or something. That way you know that the differences are JUST the pieces required to build a dll or static lib.