#if MYCONSTANT
CallAGivenFunction();
#else
CallAnotherFunction();
#endif
So, if I want the first branch to be compiled (and seen by the Intellisense), I will define a preprocessor constant called MYCONSTANT; otherwise (by doing nothing), I will have the second branch be compiled.
Looking through the documentation I understood that I should create a file named Directory.build.props in the same folder as my .csproj, and that file should have
<Project>
<PropertyGroup>
<DefineConstants>MYCONSTANT</DefineConstants>
</PropertyGroup>
</Project>
However after doing that, the code in the #if clause CallAGivenFunction();
is still greyed out (i.e. Rider does not recognize the preprocessor constant I have defined).
What am I doing wrong?
Within your .csproj file, some preprocessor directives are defined using the same <DefineConstants></DefineConstants>
element that you are using within Directory.build.props.
The element within .csproj overrides anything you create within Directory.build.props
For your own constants to be be taken into account, you need to precede the element in .csproj with $(DefineConstants)
(for example)
<DefineConstants>$(DefineConstants);DEBUG;TRACE;</DefineConstants>