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

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.

Related

Exclude files from Eclipse Indexing that are included in the build

This question provides good answers to the question of excluding files from indexing that are also excluded from a build. An open question remains: how does one prevent files that are part of the build from populating the code-completion or code-insight functions?
My use-case is a TrueSTUDIO (was System Workbench, was bare Eclipse) project which includes some modules from another project. They are wrapped in safe-to-use stubs and wrappers and should never be called directly. The external modules cannot be edited because they must stay in sync with the other project, so their filenames and other symbols clash confusingly with the current project's. When using code completion to include a header or complete a function name, the filenames and function names of the modules that are not to be used directly appear in the completion lists.
I wish to continue to include the modules in my builds, but not have any of their contents appear in the code-complete/insight features.
I see in Project Properties -> C/C++ General -> Indexer there are options to configure the indexer to use a different build configuration. This is promising, but will probably quickly lead to a indexer that is sorely out of sync with the primary build configuration.
Any advice on a practical method?
The only way I found to exclude files from Eclipse indexing is using the abovementioned Indexer-specific build configuration. In my case, it helped with the annoying problem of indexer freezing on .cu (NVidia CUDA) files.
This is how it works:
Prepare a new (Indexer-specific) build configuration.
Exclude unwanted source files from this configuration using the
Source Location exclude filter.
Let Indexer use this particular build configuration.
Eclipse configuration is a bit tricky with Indexer, so this is a step-by-step guide (as for Eclipse 2021-09):
Preparing a new build configuration:
Project->Build Configurations->Manage->New:
Give it a name, e.g., "4indexer".
Select "Copy settings from" with your preferred configuration. In my case, "Debug" worked just fine.
Excluding unwanted source files:
Project->Properties->Paths and Symbols->Source Location:
Select "4indexer" as the configuration to be managed on the top of the properties window.
Apply an exclusion pattern of your choice. In my case, I added "*.cu" at the end of the "Source Folder Exclusion Patterns" list by clicking Add... button and typing *.cu in the "Add Exclusion Pattern" text field.
Reconfiguring Indexer:
Window->Preferences->C/C++->Indexer:
Allow any Indexer to work with a project-specific build configuration (it was tricky to figure it out): check the "Use the build configuration specified in the project's indexer settings" radio button.
Project->Properties->C/C++ General->Indexer:
Check the "Enable project specific settings".
Select the new build configuration for your project Indexer: check the "Use a fixed build configuration" and select "4indexer" from the drop-down list below.
I also unchecked the "Index source files not included in the build", but I'm not sure if it is necessary.
Sometimes Indexer is trying to reindex a project as you try to reconfigure it, freezing Eclipse. So, I turned it on and off and restarted Eclipse a few times.

Visual Studio Installer Project Custom Action based on Build Configuration

Is it possible in an Installer Project to conditionally run a Custom Action based on the project build configuration (e.g. Debug, Release, etc.)?
Also to include/exclude files based on the Build Configuration?
Can I do any of these in Visual Studio 2017 or by manually editing the .vdproj file?
Once you have defined your project, let's suppose the custom action is a .NET installer project (it's not mandatory, but it's like that in my sample).
Just go the the list of Custom Actions (right-click on Project/View/Custom Actions), select your special custom action, and in the "Condition" property in the property grid, you can use the following test:
OriginalDatabase >< "Debug"
The funny syntax (>< means "contains") is documented in Conditional Statement Syntax, OriginalDatabase (case-sensitive) is a property that contains the full path name of the .msi file path that's being installed.
This is documented in Windows Installer's Property Reference. You can use this type of syntax in all Condition properties that are defined on various items (custom actions, files, etc.). Note "Debug" may be too simple as a discriminant piece of text, but you get the idea.
Of course, that supposes you've changed the .msi output name to include the "Debug" text, in Debug configuration, something like this:
Another option would be to always embed the custom action, but do nothing in it if some property is set (to indicate release mode for example). You can use CustomActionData to pass information to custom actions.

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.

Reset property page settings Visual Studio C 2010 Express

I made some changes to the Property Pages/Configuration Properties a long time ago and I'd like to reset them. I changed stuff like the output directory, code generation settings, etc.
I've tried resetting all environment settings from the Import and Export Settings Wizard. I've also tried the devenv /resetsettings command. Both of which did not work. Reinstalling doesn't work either. May I get some advice on how to restore everything back to the default.
Thank you.
If I understand you correctly, you are trying to revert to old settings for the Project -> Properties.
This information is stored in the project itself, not in Visual Studio. Look for a file with the extension vcxproj in the solution folder.
You can edit it with Notepad (notepad++), or - you can edit it inside Visual Studio, by
right-click the project, unload it, then edit project file, then reload project
Be careful how you edit these settings.
For best results, create a new solution, with a new project, and compare the settings from the newly created project with the existing one.
edit: on my computer (I have VS Ultimate I think, but it shouldn't matter):
To edit, go to Project -> Properties -> VC++ Directories, and on each, at the end of the line, press the arrow down, and click Edit...
VC++ directories:
$(VCInstallDir)bin
$(WindowsSdkDir)bin\NETFX 4.0 Tools
$(WindowsSdkDir)bin
$(VSInstallDir)Common7\Tools\bin
$(VSInstallDir)Common7\tools
Include Directories:
$(VCInstallDir)include
$(VCInstallDir)atlmfc\include
$(WindowsSdkDir)include
$(FrameworkSDKDir)\include
from what I see in the directions you pointed out, all you have to do is remove from your list, the directories that you no longer want.
In c/c++ -> Code Generation ->
enable minimal rebuild: NO
enable c++ exceptions: YES (/EHSC)
Basic Runtime Checks - Both
/MTd
...
General -> Output directory:
not sure what is the default, I would put something like
$(SolutionDir)bin\$(Platform)\$(Configuration)\
Also, there seems to be a property sheet that may have been added to your project...
You can generally see the Property Manager from View -> Properties Window (F4).
here, you can expand the project configurations, and simply delete any property sheets you may not want (I expect a new project to have no property sheets).

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

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.