Asp.net发布版本与调试版本
如何确定我的应用是否被编译为“release”而不是“debug”?我去了VS 2008项目属性>生成,并将配置从调试到发布,但我注意到没有改变?这是一个ASP.NET项目。Asp.net发布版本与调试版本
对于Web.config中的一个debug,将被设置为true,但是您也可以在发布应用程序中实际设置它。
在调试然而定义像DEBUG设置,所以很简单的事:
bool is_debug;
#ifdef DEBUG
is_debug = true;
#else
is_debug = false;
#endif
只有当你明确地设置它时,debug才会在Web.config中设置,或者你点击F5运行网站并允许它更改配置文件。此设置不是指示选择了哪个*构建配置*。 – Gromer 2009-05-21 04:28:23
如果你想知道如果DLL是建在调试模式下,使用debug属性,那么你最好的选择就是反思。
从“How to tell if an existing assembly is debug or release”摘自:
Assembly assembly = Assembly.GetAssembly(GetType());
bool debug = false;
foreach (var attribute in assembly.GetCustomAttributes(false)){
if (attribute.GetType() == typeof(System.Diagnostics.DebuggableAttribute)){
if (((System.Diagnostics.DebuggableAttribute)attribute)
.IsJITTrackingEnabled){
debug = true;
break;
}
}
}
这将让正在调用该代码的程序集(实际上本身),然后调试布尔值设置为true,如果组件在调试模式下进行编译,否则它是错误的。
这可以很容易地放入控制台应用程序(如在链接的例子中),然后你传递你想检查的DLL/EXE的路径。你会从这样的路径加载程序集:
Assembly assembly =
Assembly.LoadFile(System.IO.Path.GetFullPath(m_DllPath.Text));
你需要寻找比IsJITTrackingEnabled更多 - 这是完全独立的代码是否被编译优化和JIT优化。
此外,如果您在发布模式下编译并选择DebugOutput以“none”以外的其他任何值,DebuggableAttribute就会出现。
请参阅我的文章: How to Tell if an Assembly is Debug or Release和 How to identify if the DLL is Debug or Release build (in .NET)
同类者问题在#1,一个问题,和很多很多不同的答案: http://stackoverflow.com/questions/654450/programatically-检测释放调试模式网络 http://stackoverflow.com/questions/798971/how-to-idenfiy-if-the-dll-is-debug-or-release-build-in-net http://stackoverflow.com/questions/194616/how-to-tell-if-net-app-was-compiled-in-debug-or-release-mode http://stackoverflow.com/questions/50900/best-way-to-detect-a-release-build-from-a-debug-build-net http://stackoverflow.com/questions/890459/ asp-net-release-build-vs-debug-build – Kiquenet 2011-02-03 19:51:42