By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,248 Members | 882 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,248 IT Pros & Developers. It's quick & easy.

Conditionally exclude from Release build

P: n/a
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?
Nov 16 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hello

Yes you have

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

Best regards,
Sherif

"Nevyn Twyll" <as****@hotmail.com> wrote in message
news:ei**************@TK2MSFTNGP12.phx.gbl...
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?

Nov 16 '05 #2

P: n/a
did you look hard enough? :)

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

hope that helps.

"Nevyn Twyll" wrote:
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?

Nov 16 '05 #3

P: n/a
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.
"Nevyn Twyll" <as****@hotmail.com> wrote in message
news:ei**************@TK2MSFTNGP12.phx.gbl...
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?

Nov 16 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.