简体   繁体   中英

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?

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

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:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM