编程检测发布/调试模式(.NET) [英] Programmatically detecting Release/Debug mode (.NET)
问题描述
可能重复:
如何找出如果一个.NET程序集是与跟踪或调试标志编译
可能重复:
<一href="http://stackoverflow.com/questions/798971/how-to-idenfiy-if-the-dll-is-debug-or-release-build-in-net">How以idenfiy如果DLL是调试或发布版本(在.NET)
什么是编程检查当前组件是在调试编译或发布模式的最简单的方法是什么?
布尔isDebugMode = FALSE;
#如果调试
isDebugMode = TRUE;
#ENDIF
如果你想调试程序和发布版本,你应该做这样的不同的行为:
#如果DEBUG
INT []数据=新INT [] {1,2,3,4};
#其他
INT []数据= GetInputData();
#ENDIF
INT总和=数据[0];
的for(int i = 1; I&LT; data.Length;我++)
{
总和+ =数据[I]
}
或者,如果你想要做某些检查的功能调试版本,你可以做到这一点是这样的:
公众诠释总和(INT []数据)
{
Debug.Assert的(data.Length大于0);
INT总和=数据[0];
的for(int i = 1; I&LT; data.Length;我++)
{
总和+ =数据[I]
}
返回总和;
}
在 Debug.Assert的
将不会被包含在发布版本。
Possible Duplicate:
How to find out if a .NET assembly was compiled with the TRACE or DEBUG flag
Possible Duplicate:
How to idenfiy if the DLL is Debug or Release build (in .NET)
What's the easiest way to programmatically check if the current assembly was compiled in Debug or Release mode?
Boolean isDebugMode = false;
#if DEBUG
isDebugMode = true;
#endif
If you want to program different behavior between debug and release builds you should do it like this:
#if DEBUG
int[] data = new int[] {1, 2, 3, 4};
#else
int[] data = GetInputData();
#endif
int sum = data[0];
for (int i= 1; i < data.Length; i++)
{
sum += data[i];
}
Or if you want to do certain checks on debug versions of functions you could do it like this:
public int Sum(int[] data)
{
Debug.Assert(data.Length > 0);
int sum = data[0];
for (int i= 1; i < data.Length; i++)
{
sum += data[i];
}
return sum;
}
The Debug.Assert
will not be included in the release build.
这篇关于编程检测发布/调试模式(.NET)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!