Is there a tool that allows you to custom build a vcproj? - c++

We have several Visual Studio projects, and we would like to:
enable/disable some defines on some of the projects
add/remove include paths
change output directories ( lib dependencies ) for libs
In a nutshell, we would like to be able to support all of the things above, without having to have a lot of configurations in the solution file. Is there some tool which allows us to do that, perhaps from command-line, if VS doesn't support such a thing? We are using VS2005 Professional.

You can use property sheets to share build settings accross several projects. Projects can use multiple property sheets and property sheets can inherit from each other allowing you to mix and match however you need to.
In the build settings dialog for you project, you will need change the settings you are concerned about to <inherit from project defaults>. In this context, default means to take the value from the property sheet. Any default settings will appear non-bold, while settings that customized for the project are bold.
After that, you can change the values in the property sheets and have those changes applied to all the projects that use them at once.

You can use CMake to generate a VS .sln and .vcproj files.

Related

How do you seamlessly integrate a third party library into Visual Studio 2017?

I want to take libFoobar/lib and libFoobar/include and tell VS2017 to make compiling and linking with them work by default for all projects.
In earlier versions there was a global setting for compiler directories but I believe they deprecated that and made it completely project level.
You can manually add a third party library to a project by configuring its project settings
Under C/C++ / additional include directories and linker / input / additional dependencies.
I don't want to have to store or memorize the names and locations of all of the .lib files or /include directories that I might need and manually re-enter them every time I start a new project or have to recreate an existing project.
There may be a way to create and maintain a project template which would be a solution.
You can add .libs to the project from the source code via #pragma comment(lib, "libFoobar.lib"). The most convenient overall method that I've got so far is to add /libFoobar/lib to the PATH variable, add the libs via #pragma to each header file, and manually add the /include directory to each project. But that's a hack.
I did try to use "INCLUDE" and "LIBPATH" environment variables but they did not exist and adding them did nothing:
https://learn.microsoft.com/en-us/cpp/build/reference/cl-environment-variables?view=vs-2019
They might be valid on 2019 only.
Yes, project templates are a thing, and should accomplish this.
Here's some documentation I found by Googling "VS project templates":
How to: Create project templates
Instead of making project templates you can modify the default project property sheets.
Go to View->Other window->Property manager then open one of the nodes for the machine type you are working with (debug and release builds share the actual property sheet file). Right click on Microsoft.Cpp..user and select Properties, you can then make changes just like any other property sheet and the settings will be picked up by projects generated using the default wizards.
This is the replacement system for the mentioned prior global setting.

Visual Studio: C++ Project Include Paths sharing over Repository

I was wondering how should I add my library include paths and linker paths in Visual Studio so that when I add my project to a repository, another developer checking out my project would not need to go through all the include paths and change them for his own machine. So, I am kind of looking at something like ${MY_THIRD_PARTY_LIB_INCLUDE_PATH}\tbb\include and ${MY_THIRD_PARTY_LIB_LINKER_PATH}\tbb\lib\ia32\vc11 so that someone accessing the project can just change MY_THIRD_PARTY_LIB_INCLUDE_PATH and MY_THIRD_PARTY_LIB_LINKER_PATH and everything works as intended. Can somebody suggest a best practice around this or may be how to accomplish what I just described?
In VisualStudio 2012 I use Project Properties
So if you go to the Propery Manager you Add a new Project Property Sheet to you project. From there, a couple of things can be set
User Macros - We create a macro here and put in a path for our environment. We crate a Macro called CUSTOM_DEBUG_PATHS, and then in the project we set the Debugging->Environment to path=$(PLA_DEBUG_PATHS);$(PATH)
The other thing that we do in the Project Property Sheet is change our Include and Library directories. We have everyone use relative paths, but you could put in an environment variable or something in here so that everyone could use the same file.

Apply a property change to all DLL projects in a solution

I have a solution containing approximately 150 projects, including static libraries, dynamic libraries and executables as well as a few Makefile based projects for good measure, so I have an extended version of this guy's problem.
I need to apply a change to the linker page of all EXE and DLL projects (add /FIXED:NO for the benefit of Rational Purify). Is there a way I can do this easily, e.g. with the help of a macro?
I would modify the project files directly - they are XML after all, and you can easily discover what change needs to be done in them to add the flag. Then you can write an e.g. Python script to modify all project files.
You can make a common project property, Then you can modify the related projects to inherit this common property, so when next time you just need to modify the common project property, then the projects inherit it will automatically sync the new settings. Property Sheets (C++)
To apply project settings that are defined in property sheets using the Inherited Project Property Sheets property:
To apply project settings that are defined in property sheets using the Inherited Project Property Sheets property
Open your project in the Visual Studio IDE.
In Solution Explorer, right-click the node for the project or the property sheet that will inherit the project configuration.
On the shortcut menu, click Properties. The property pages for your project will appear.
Use the Configuration control to specify which project configuration to apply the project settings.
In the Inherited Project Property Sheets field of the General property page, enter the path to the property sheet that contains the settings you want to inherit.
Click Apply.
This is exactly the sort of thing property sheets were designed for. Create a hierarchy of property sheets which contain settings that are common to certain types of project, then attach them to the relevant projects, using property manager (View menu -> Property manager).
For example:
All.props -> settings common to all projects
Debug.props -> settings common only to debug builds
Release.props -> settings common only to release builds
Static.props -> settings common only to static library projects
Dynamic.props -> settings common only to dynamic library projects
Executable.props -> settings common only to executable projects
This will require a small amount of work up-front, to add the property sheets to your existing projects. Then, whenever you create a new project, all you have to do is attach the relevant property sheets. Maintenance becomes easy - to change a setting and have that change apply to all executable projects, you simply update the property sheet Executable.props.
Note: property sheets are sorted according to their place in the hierarchy, so that a setting which is in a property sheet higher up will override the same setting in a sheet which is lower down the list. This is a big advantage - you can place your default settings in All.props (from my example above), and then override settings in more specific property sheets. If you have a one-off project with its own unique settings, then modifying the project settings directly will override all property sheets.

Visual studio 2010 - retain project properties between different build configurations?

I have two projects in my solution. I am currently using the default configuration mode which is 'Debug'. When I want to do a 'Release' build, I switch to Release-mode and then I see all my previous projects properties are set to default, meaning I have to add all properties again manually to this mode.
Is there a convenient way to solve this in VS2010, for example to copy all properties like include paths, preprocessor macros, build macros, etc from 'Debug' to 'Release' mode?
Configuration settings are stored in .vcproj / .vcxproj file. You could open it in some text editor and copy some settings manually, but it wouldn't be convenient. For now you could just open projects properties and copy these settings while switching Debug / Release configuration in the upper left corner of that window.
Next time when you are setting properties that are intended to be the same for all configurations, choose Configuration: All Configurations to avoid troubles.
Property sheets can solve this and a few other property-related issues with ease.
In short, all the properties in a project are just nodes in an XML document, and the property group nodes can have a condition attribute. They're easy to change in any text editor, but a lesser-known feature is the ability to import other XML documents, which can provide settings (for all but a few project-specific ones).
This blog post has a good tutorial on using project sheets, and some more info in this question. You can create them in Visual Studio, edit them (including copying your existing project settings over), then attach them to your project with the property manager (not the property window).
The groups in your property sheet use the same syntax as regular settings, and can be set for all configurations or filtered to only apply on some. They can also be filtered by project name and a few other things, using VS' variable and condition system. For example, I use:
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>
<Optimization>Disabled</Optimization>
<EnablePREfast>true</EnablePREfast>
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
</ClCompile>
</ItemDefinitionGroup>
for some of my builds, to apply the same settings to all project (full file here).
One of the most convenient uses is giving the build directory in the file, so all your projects build uniformly into the same directory (make sure to use the project name for the output).
Managing almost all the properties across multiple different builds (debug, release, win32, x64 etc.) can be accomplished with a single collection of settings by using Macros.
Thus, before editing a project settings, make sure you've set Configurations to All Configurations and, Platform: to All Platforms. Now almost all settings can be done in this way, across all the different configurations. Say, you want different configurations and platforms to use different versions of various libraries. Assuming you are using a naming convention that's consistent across all projects, you can then use:
Additional Library Directories: ..\..\foo\bar\lib\$(Platform)_$(Configuration)
You can see what macros will expand to, by hitting the edit button, and then clicking on the Macros>> button.
You could also recreate the new mode you want using the configuration manager and then you can choose from which configuration you want to copy all the settings.

How to set configuration properties in VS once and for all?

In VS 2010RC I have to specify configuration properties and specifically included path every time I'm creating new project. Is there a way to do it just once for all future projects?
I'm asking this for a reason that I'm starting to use Boost libraries and I have to specify all those paths every time I'm creating project which is bit tedious.
The VC++ Directories (which is what I think you're looking to configure) have been moved to a property sheet to make them more MSBuild-friendly.
A snippet from http://blogs.msdn.com/vsproject/archive/2009/07/07/vc-directories.aspx:
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.
See the following for more details on property sheets in VC++ 2010:
http://blogs.msdn.com/vsproject/archive/2009/06/23/inherited-properties-and-property-sheets.aspx
I usually copy the *.vcproj and *.sln files and then edit them, changing files and project names. If you create projects frequently, you may want to copy the files, edit them to the bare minimum and save as read-only stencils.