使用预处理器检查应用程序是否是 winforms 或 asp.net
是否可以在程序集中检查哪些客户端(winforms 应用程序或 asp.net 页面)正在运行它? 我想添加一些方法,但仅限于特定客户端。
我知道,有预定义的DEBUG(#if DEBUG)。在哪里可以找到完整列表,我可以使用预处理器检查什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了扩展 m0sa 的答案,预处理器指令基本上只是传递给编译器的字符串。
如果您愿意,您可以添加新的构建配置(例如:您可以制作 WebDebug/AnyCPU、WinformsDebug/AnyCPU、WebRelease/AnyCPU 等,而不是 Debug/AnyCPU 和 Release/AnyCPU)。
然后,在项目的属性页面中,对于每个配置,您可以在“条件编译符号”字段中提供一个值。例如,对于 WebDebug 和 WebRelease,您可以提供条件符号 WEB。然后,您将能够使用:
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:
您将需要多个构建配置,并为每个配置定义不同的预处理器指令。您可以在项目“属性”页面的“构建”选项卡中设置条件预处理器指令。没有定义其他指令,只有可以在同一选项卡中打开和关闭的 DEBUG 指令(与 TRACE 指令一起)。请注意,DEBUG 它不是为“release”构建配置定义的。这是您需要执行的操作才能构建不同版本的程序集。
参考文献:
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: