Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check using preprocessor if app is a winforms or asp.net

Is this possible to check in assembly what client (winforms app or asp.net page) is running it? I want to add some methods but only for specific client.

I know, there is predefined DEBUG (#if DEBUG). Where can I find full list, what can I check using preprocessor?

like image 512
lkurylo Avatar asked Jun 12 '26 10:06

lkurylo


2 Answers

To expand on m0sa's answer, preprocessor directives are basically just a string passed to the compiler.

If you are so inclined, you can add new build configurations (example: instead of Debug/AnyCPU and Release/AnyCPU, you could make WebDebug/AnyCPU, WinformsDebug/AnyCPU, WebRelease/AnyCPU, etc).

Then in the properties page of your project, for each configuration you could provide a value in the 'Conditional compilation symbols' field. For example, for WebDebug and WebRelease, you could provide the conditional symbol WEB. Then, you would be able to use:

#if WEB
using MyNamespace.WebStuff;
#endif
like image 188
tuxedo25 Avatar answered Jun 14 '26 00:06

tuxedo25


You will need multiple build configurations for that and define different a preprocessor directive for each one. You can set the conditional preprocessor directives in the Build tab of the project Properties page.There are no other directives defined, just the DEBUG directive which you can turn on and off (together with the TRACE directive) in the same tab. Note that DEBUG it is not defined for the "release" build configuration. This is kind of what you will need to do to enable different versions of the assembly to be built.

References:

  • MSDN
  • www.davidarno.org <-- see this one for a more visual description
like image 24
m0sa Avatar answered Jun 13 '26 23:06

m0sa