1

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?

manabreak
  • 5,415
  • 7
  • 39
  • 96
  • 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 Answers3

6

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>
Dmitry Ledentsov
  • 3,620
  • 18
  • 28
2

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.

Niall
  • 30,036
  • 10
  • 99
  • 142
0

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:

The project site is: http://www.cmake.org

Community
  • 1
  • 1
elcuco
  • 8,948
  • 9
  • 47
  • 69