简体   繁体   English

如果app是winforms或asp.net,请使用预处理器进行检查

[英]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? 这是否可以检查汇编哪些客户端(winforms app或asp.net页面)正在运行它? I want to add some methods but only for specific client. 我想添加一些方法,但仅限于特定客户端。

I know, there is predefined DEBUG (#if DEBUG). 我知道,有预定义的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. 为了扩展m0sa的答案,预处理器指令基本上只是传递给编译器的字符串。

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). 如果您如此倾向,可以添加新的构建配置(例如:代替Debug / AnyCPU和Release / AnyCPU,您可以制作WebDebug / AnyCPU,WinformsDebug / AnyCPU,WebRelease / AnyCPU等)。

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 . 例如,对于WebDebug和WebRelease,您可以提供条件符号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. 您可以在项目“属性”页面的“构建”选项卡中设置条件预处理程序指令。没有定义其他指令,只能在同一选项卡中打开和关闭(与TRACE指令一起)的DEBUG指令。 Note that DEBUG it is not defined for the "release" build configuration. 请注意,DEBUG没有为“发布”构建配置定义。 This is kind of what you will need to do to enable different versions of the assembly to be built. 这是您需要执行的操作,以便能够构建不同版本的程序集。

References: 参考文献:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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