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

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+

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.

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

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.

Custom Wizard (C/C++) VS10

i'm trying to create a template for a project (GTK+), where I don't want to have to include always the header-paths. As far as I understand the only possibility to do that in C is to create a custom wizard.
I already created one, and added "Additional Libraries" (in the function AddConfig()). But I can't seem to find how to add VC++ Directories. I guess I could try to add the header-files directly in the project, but I'd rather just "link" to them.
Thanks.
Such tasks can be solved much easier by means of custom property sheets. A property sheet, once configured and saved, can be added to any C++ project by two mouse clicks in the property manager.

Force VSProps settings to override project settings

I have a vsprops file that defines the optimizations all of our projects should be built with for Visual Studio 2008. If I set the properties for the project to "inherit from parent of project defaults" it works, and fills them in the vcproj file. However, this doesn't protect me from a developer checking in a project file that changes the optimizations. In this case, the project settings are used over the vsprops settings. I need to make it so that vsprops always takes precedence over what is in the vcproj file. Is this possible? Other workarounds are also welcome.
Hmya, that's just not how Visual Studio was designed. It is quite free from "boss override" switches, it gives its user unfettered access to configuration settings. Which ought to make sense to you, a developer can do far more damage with his code than with tinkering settings. If a dev intentionally changes an optimization setting then, surely, it is because he profiled the code and determined a better setting.
Anyhoo, Visual Studio isn't just useful to the dev, it is also useful to you. Write a little utility that parses the .vcproj file and checks if the optimization settings were overridden. It is a simple .xml file, you'll need about 5 lines of code. Run it in a pre-build event on your build grunt and fail the build if you deem it inappropriate. Dealing with the pissed-off developer cannot be automated however.
The only advice I can give is, if you open up the Property Manager for the project, and Right Click on one of the Configuration folders, it should popup a menu with an item called "Overidden Properties..." which in turn opens a dialog box that lists each property set in the project configuration that overrides a property sheet property sheet - along with the facility to select some or all, and delete the overrides.

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