work.bin
work.bin

Reputation: 1108

How to include/exclude source files from the project depending on the build configuration?

I want to include a file in the project only under the 'Debug' build configuration and not in the 'Release' build. How can I do that via the IDE?

I am already able to achieve the above by manually editing the '*.vcxproj ' file.

<ClCompile Include="..\..\..\..\dbg_helper.c" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"/>

I am using Microsoft Visual Studio Express 2013 for Windows Desktop (Version 12.0.21005.1 REL).

Upvotes: 7

Views: 1525

Answers (2)

Anateus
Anateus

Reputation: 447

If you only want to exclude it from the build and not from the entire project tree, you can do it from UI.

Just edit the file properties.

file properties file properties

Now, you can change to the desired configuration, for which you want to edit its properties. enter image description here enter image description here

Exclude your file for all configurations and platforms. enter image description here And then include it only for the configuration you want it to build. enter image description here

Upvotes: 3

Tore &#216;stergaard
Tore &#216;stergaard

Reputation: 4602

Unloading the project and edit the file by hand is technically done through the IDE, so I guess that you are looking for way to do this through the Project Properties, which is not possible.

In C# you can decorate your class with ConditionalAttribute like so:

[Conditional("DEBUG")] // or another constant you use in your configurations
public class MyClass {
    ...
}

And the similar for C++:

#if DEBUG // or another constant you use in your configurations
...
#endif

I would however not recommend using this too much as you can run into problems.

Upvotes: -1

Related Questions