Set project-wide preprocessor defines

Is it possible to set custom preprocessor defines for a project? We have some code within #if CUSTOM_DEFINE #endif blocks that are not visible to Rider (greyed out). This means that any refactoring doesn't include this code and causes bugs.

This discussion claims that Rider will only parse the current context's block because 1) code in blocks may not be correct because people use them to comment and 2) it is unfeasible to check all branches.

It seems this should at least be optional as these reasons do not apply to all projects (e.g., if you don't use defines for commenting and don't have too many of them).

1 comment
Comment actions Permalink

I am currently missing this feature and I might not be able to use Rider because of this issue.

To provide my specific use case:
I am using Rider for a Unity multiplayer game project. To keep a shared code base I have set up IS_SERVER and IS_CLIENT preprocessor directives to isolate logic that should only be executed on the server or the client. My build pipeline allows to create different builds using the appropriate defines.

However, inside Rider there is no clean way to work on the files without switching back and forth the defines inside the Unity editor, causing drastically longer iteration cycles and increased potential of user error.

I want to have intellisense of server and client code at all times and refactoring should be applied to all sections as some of the conditional logic uses the same interfaces / data structures.


Possible solutions could be:

  1. Treating #if sections as if they were active all the time
  2. Allowing to define a symbol inside Rider which is not active in Unity (so that build pipeline and starting in the editor doesn't break) and rewriting all #if sections to #if IS_CLIENT || RIDER

Please sign in to leave a comment.