Sharing Build Configuration Settings Between Project Files
Update: Oh snap… nCrunch isn’t smart enough to pull in the external configurations like this, and so it won’t run any of my tests. Gotta find plan B.
As we’ve added new projects to our solution and new build environments, it has become increasingly difficult to maintain consistency in our settings across all projects. Here is how we addressed it.
Added a new MSBuild target file (CommonBuildConfigurationSettings.target) to the solution to contain these settings.
Added the shared settings to CommonBuildConfigurationSettings.target. Note that we’ve added build settings for each of the project build configurations we have. To add a new project build configuration, a new section can simply be added here:
Removed these settings from the individual projects and replaced them with an import of the target file.
</div>
The benefits:
- A single point to modify and add build configuration settings.
- These settings can still be viewed by going to the Build tab of the Project Properties.
- The solution configuration manager can still see all of the build configurations so you can still wire up the project configurations with the solution configurations as before.
- The common shared settings can be overridden for a specific project if needed by modifying the values visible on the Build tab of the Project Properties.
The downsides:
- Updating shared settings must be done through the target file and not the Build tab of the Project Properties. If someone forgets this and modifies through the Build tab, they will unintentially create an override for that one project.
- Target files are cached in Visual Studio, so any changes to the shared configuration target file are not realized in Visual Studio until the solution is closed and reloaded.
- Newly added projects have to be modified with the steps above.