#if WINDOWS preprocessor directive does not work in Rider
In C#, the #if WINDOWS preprocessor directive does not recognise that I'm running Rider in Windows. The code enclosed by the directive is disabled and so won't compile.
This is true of a Maui application and a console application. Yet it works fine in Visual Studio. https://youtrack.jetbrains.com/issue/RIDER-96278/.NET-MAUI-Multi-targeting-platform-specific-preprocessor-directives-not-recognized-by-IDE looks relevant, and its status is Answered. But I don't see the answer.
What is the fix?
Please sign in to leave a comment.
I changed the visibility if the attached video. Indeed, it was hidden. Could you please try the solution shown here (to switch target context) https://youtrack.jetbrains.com/issue/RIDER-96278/.NET-MAUI-Multi-targeting-platform-specific-preprocessor-directives-not-recognized-by-IDE#focus=Comments-27-7904126.0-0? Can it help?
Happy New Year, Sofia!
That fixes it for Maui, thanks. The target framework was set to Mac Catalyst. I switched it to Windows. I was looking for such a feature, but it's in a different place from Visual Studio and I did not spot it.
That fix is of course specific to Maui. Can you tell me the fix for Console applications please?
I notice that #if WINDOWS also does not work for me in a WPF application. However, that does not matter, as WPF only works on Windows.
Cheers,
Simon
I'd like to add that context change dropdown is unavailable during debugging.
Is there a solution to switch context during debugging?
Vladimir Bukreev, could you please share more details about the use case why you need to switch context and what kind of context do you mean here?
Sofia, sorry for being unclear.
During debugging, when I step into source code of a NuGet package (and the package contains source code) that contains #if NET (#if NETFRAMEWORK) preprocessor directives, I can make Rider make one or another platform (framework) current. Rider defaults to .NET Framework and shows all .NET source code grayed out and there is no “context” dropdown for choosing a target framework at the bottom of the editor window.
During my testing I've noticed that the dropdown disappears only for NuGet binaries containing source code. If you step through your own multitargeted project or if you step through disassembled source code, dropdown is present and you can change the target framework.