How to set custom preprocessor flags in C# when compiling for release?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By kitfox

I’ve recently delved into creating EditorPlugins to make it easier to edit custom resources I’ve created. Unfortunately, having any class that extends EditorPlugins prevents me from exporting my projects - I presume because Godot is linking against a library that does not include a symbol for the EditorPlugin class for exports. So I would like to find a way to comment out my EditorPlugin when exporting my projects but still have it there when I compile for debug so that my plugin can still be used by the editor.

The C# preprocessor seemed to be the answer to this problem and the docs even say that I can define my custom flags by adding a keyword to the Export/Features panel:

Unfortunately, this is not working for me. I added the keyword ‘export’ to the Features panel and used #if GODOT_EXPORT to try and use it, but the flag seems to be ignored.

    #if GODOT_EXPORT
        richTextLabel.BbcodeText = "release";
    #else
        richTextLabel.BbcodeText = "debug";
    #endif

How do I set my custom flag? Is there some other way to not have this code compiled into any exported version of my project?

:bust_in_silhouette: Reply From: kelaia

Try this way:
enter image description here
enter image description here

How do I have that set only when I export? That looks like it will be set regardless of the target.

kitfox | 2022-02-02 03:35

i think there is a DEBUG flag that you can use.

#if DEBUG
#define NEW_FLAG
#endif

kelaia | 2022-02-02 12:19

That does seem to work to solve this problem. Still, it would be nice to know why the Features section does not seem to be working.

kitfox | 2022-02-02 15:50