Asp.net 发布构建与调试构建
如何确定我的应用程序是否编译为“发布”而不是“调试”? 我去VS 2008项目属性> 构建并设置从调试到发布的配置,但我注意到没有变化? 这是一个 ASP.NET 项目。
How do I determine if my app was compiled as "release" instead of "debug"? I went to VS 2008 Project Properties > Build and set the configuration from Debug to Release but I noticed no change? This is an ASP.NET project.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
HttpContext.IsDebuggingEnabled
HttpContext.IsDebuggingEnabled
如果您想知道 dll 是否是在调试模式下构建的,并且具有调试属性,那么您最好的选择是反射。
取自“如何判断现有程序集是调试还是发布”:
这将获取调用该代码的程序集(实际上本身有效),然后如果该程序集是在调试模式下编译的,则将调试布尔值设置为 true,否则为 false。
这可以很容易地放入控制台应用程序中(如链接的示例中所示),然后传入要检查的 dll/exe 的路径。 您可以从如下路径加载程序集:
If you want to know if the dll was built in Debug mode, with the debug attributes, then your best bet is reflection.
Taken from "How to tell if an existing assembly is debug or release":
This will get the assembly that is calling that code (in effect itself), and then set the debug boolean to true if the assembly was compiled in debug mode, otherwise it's false.
This could easily be dropped into a console app (as in the linked example), and then you pass in the path of the dll/exe you want to check. You would load the assembly from a path like this:
对于 Web.config 中的一个,调试将设置为 true,但是您实际上也可以在发布应用程序中设置它。
然而在调试中设置了像 DEBUG 这样的定义,所以很简单:
For one in Web.config debug will be set to true, however you can actually set this in a release application too.
In debug however defines like DEBUG are set, so it's simple to do:
您需要寻找的不仅仅是 IsJITTrackingEnabled - 它完全独立于代码是否经过编译以进行优化和 JIT 优化。
此外,如果您在发布模式下编译并选择 DebugOutput 为“none”以外的任何值,则 DebuggableAttribute 也会出现。
请参考我的帖子:
如何判断是否程序集正在调试或发布并且
如何确定 DLL 是调试版本还是发布版本(在 .NET 中)
You need to look for more than IsJITTrackingEnabled - which is completely independent of whether or not the code is compiled for optimization and JIT Optimization.
Also, the DebuggableAttribute is present if you compile in Release mode and choose DebugOutput to anything other than "none".
Please refer to my posts:
How to Tell if an Assembly is Debug or Release and
How to identify if the DLL is Debug or Release build (in .NET)