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.
Related
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.
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.
I always add the _CRT_SECURE_NO_WARNINGS to all of my C/C++ projects in the Preprocessor Definition tab in the Project Properties. There is the drop-down for <edit> and <inherit from parent or project defaults>. How do I change the values of the project defaults. I would think it is an XML file hidden somewhere, or that file needs to be created. Anyone know the location?
View -> Property Manager, then expand a project and build configuration to see the property sheets being used for that build configuration. Right-click on a property sheet and select Properties to modify the property sheet. I don't recommend modifying the built-in property sheets, however there is a .user property sheet for this purpose. You can also create your own property sheet that defines the preprocessor macro, then add your new property sheet to the list for each build configuration.
My answer and description here will neatly solve this. It uses property sheets, as Hans Passant suggested.
The general setup is to a create a property sheet containing all of the necessary shared settings, optionally in multiple groups with conditions based on build type. You then include the property sheet from each project file.
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.
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.