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 https://github.com/JetBrains/resharper-unity/issues/125 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).

11
4 comments

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
1

Hi Pascal Blessing

Could you please tell us some more about your pipelines that allow this case? What build tool do you use? What is the structure of your solution? 

Unfortunately, it is not possible to have #if sections as always active. 

As to second point, you can define constants in a project file (csproj) using DefineConstants property (ex.<DefineConstants>HELLO</DefineConstants>) or use Directory.build.props file for defining them. If this file is located on a project level, all the defines will be available on a project level. For solution level place this file in a solution folder.

For more details please follow this article

2

I too would like a better way to work with preprocessor directives (PD) in Rider. 

We have certain NuGet packages we use for internal development that include and exclude certain interfaces/classes/enums/etc when targeting different frameworks.  Not being able to quickly switch (or simulate switching) these values during development (without changing the values of the configs) means that a good number of these files are totally greyed out in the IDE as if they were commented out.  This is a terrible development experience to say the least; and in reality, it is almost unusable.  I have to remove or comment out the PD to work with the file, then remember to put it back before publishing or testing the package.  ...you see how this can and will lead to issues...

If there was a way to toggle/simulate the values (per file/project/session), that would make working with the PDs INFINITELY better.

Does this need to become a feature request?  If so, I would suggest a high priority.

1

Hi Creed-c

Thank you. Could you bring us some more examples? What build tool do you use? What is the structure of your solution?  Or, if you would like, you can directly create a feature request in our tracker (use `Help | Report a bug` for this) with all the details. 

 

0

Please sign in to leave a comment.