I'm guessing your code is like:
void DoSomethingIfCompFlag() {
#if COMPILER_FLAG
//your code
#endif
}
This won't get optimised out, however:
partial void DoSomethingIfCompFlag();
#if COMPILER_FLAG
partial void DoSomethingIfCompFlag() {
//your code
}
#endif
The first empty method is partial, and the C#3 compiler will optimise it out.
By the way: this is basically what partial methods are for. Microsoft added code generators to their Linq designers that need to call methods that by default don't do anything.
Rather than force you to overload the method you can use a partial.
This way the partials are completely optimised out if not used and no performance is lost, rather than adding the overhead of the extra empty method call.