I have multiple build configurations in my project, and I'd like to swap some .CPP files based on the currently selected configuration. How can I do that in Visual Studio 2013?
-
If it's possible you could have different pre-processor defines for the different configurations, and one "master" source file which includes the others depending on the pre-processor macros. – Some programmer dude Jul 30 '14 at 07:49
3 Answers
In the GUI, see properties of a cpp file and set "Excluded From Build" to yes for the configurations where it's excluded.
In the project file would look like:
<ClCompile Include="my_platform_specific_file.cpp">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
true
</ExcludedFromBuild>
</ClCompile>

- 3,620
- 18
- 28
In the IDE.
Select the configuration you want to alter (either from Build > Configuration Manager
or the drop down in the toolbar. From the solution explorer, on the file you wish to; right click > Properties > Excluded from Build > Select Yes or No.
In the project file itself, locate the file being excluded
<ClCompile Include="xyz.cpp">
Add the following element;
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='MyConfiguration|Win32'">true</ExcludedFromBuild>
Where MyConfiguration
is the configuration you wish to exclude the file from.

- 30,036
- 10
- 99
- 142
This might be a good reason to start looking into more generic project managers.
I can recommend you looking into CMake , which is very powerful and can generate VisualStudio projects. The learning curve might be a high (for someone who is used to Visual Studio automation) but the gains are very high.
Some links:
- Linking different libraries for Debug and Release builds in Cmake on windows?
- http://cmaketools.codeplex.com/ - support for CMake files editing
- http://www.youtube.com/watch?v=w9sKd8f0kFo - video displaying cmake integration into VisualStudoi
- http://www.cmake.org/Wiki/CMake - random help
The project site is: http://www.cmake.org