装饰 main 方法的属性的构造函数不会在发布版本中被调用
有谁知道为什么在调试版本中调用装饰 main 方法的属性的构造函数,而不是在发布版本中调用?
如何确保在发布版本中也调用构造函数?当然无需手动调用它。
任何关于这个主题的见解将不胜感激。
Does anyone know why the constructor of an attribute decorating the main method is called in debug builds, but not in release builds?
How can I ensure that the constructor is called in release builds as well? Without calling it manually of course.
Any insight on this subject would be very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可以重现这个(在调试和发布中),当通过 IDE 执行时使用“Debug”=>;通过以下方式启用“启用 Visual Studio 托管进程”选项。在命令行中它将打印“hello”,而在 IDE 中它将打印“world”。看起来 IDE 对属性做了一些不同的反射。
这不是预期的行为,您不应依赖此行为。如果您想要执行某些特定代码:显式调用所需的代码。要获得可预测的行为,请禁用“调试”=>“启用 Visual Studio 托管进程”选项。
I can reproduce this (in both debug and release), when executed via the IDE with the "Debug" => "Enable the Visual Studio hosting process" option enabled, via the below. At the command-line it will print "hello", where-as via the IDE it will print "world". It looks like the IDE is doing some different reflection on the attributes.
This is not expected behaviour, and you should not rely on this behaviour. If you want some particular code to execute: invoke the desired code explicitly. To get predictable behaviour, disable the Debug" => "Enable the Visual Studio hosting process" option.