Conditionally exclude from Release build

  • Thread starter Thread starter Nevyn Twyll
  • Start date Start date
N

Nevyn Twyll

I have a bunch of test case classes (.cs) files in my executable.
For security and bloat reasons, I don't want them to compile into a Release
executable - only into a Debug build.

How do I conditionally exclude files or classes from my Release builds?

In old C++ we would use #ifdef ... #endif statements, but we don't have
pragmas in C# (or don't seem to).

Help?
 
Hello

Yes you have

#if DEBUG
// your debug code here
#else
// your release code here
#endif

Best regards,
Sherif
 
did you look hard enough? :)

there's #if #else #elif #endif #define #undef directives you can use in C#.

hope that helps.
 
The previous posters pointed out the existence of preprocessor directives in
C#.

However, you can also make individual methods conditional by using the
Conditional attribute, e.g.

[Conditional("Debug")]
public void foo() {
// some code
}

There are a few conditions however:

1. The method must be in a struct or class declaration (not an interface)
2. The return type must be void
3. You must not use the override modifier (virtual is OK)
4. The conditional method must not be an implementation of an interface
method.

Hope that helps.

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
 
Back
Top