thi*_*eek 92
唯一的最佳方法是检查已编译的程序集本身.Rotem Bloom 在这里找到了一个名为".NET Assembly Information"的非常有用的工具.安装它之后,它会将自己与.dll文件关联,以便自行打开.安装完成后,您只需双击程序集即可打开,它将为您提供下面屏幕截图中显示的程序集详细信息.在那里,您可以确定是否已编译调试.
希望这可以帮助..
Dav*_*ack 92
恕我直言,上述申请确实具有误导性; 它只查找IsJITTrackingEnabled,它完全独立于代码是否为优化和JIT优化而编译.
如果在Release模式下编译并选择DebugOutput为"none"以外的任何值,则存在DebuggableAttribute.
您还需要准确定义"调试"与"发布"的含义......
你的意思是应用程序配置了代码优化?你的意思是你可以附加VS/JIT调试器吗?你的意思是它生成DebugOutput?你是说它定义了DEBUG常量吗?请记住,您可以使用System.Diagnostics.Conditional()属性有条件地编译方法.
恕我直言,当有人询问程序集是否为"Debug"或"Release"时,它们的确意味着代码是否已经优化...
Sooo,你想手动或以编程方式执行此操作吗?
手动:您需要查看程序集元数据的DebuggableAttribute位掩码的值.这是怎么做的:
//元数据版本:v4.0.30319 .... // .custom instance void [mscorlib] System.Diagnostics.DebuggableAttribute ::.ctor(valuetype [mscorlib] System.Diagnostics.DebuggableAttribute/DebuggingModes)=(01 00 02 00 00 00 00 00)
以编程方式:假设您想以编程方式了解代码是否是JITOptimized,这是正确的实现:
object[] attribs = ReflectedAssembly.GetCustomAttributes(typeof(DebuggableAttribute),
false);
// If the 'DebuggableAttribute' is not found then it is definitely an OPTIMIZED build
if (attribs.Length > 0)
{
// Just because the 'DebuggableAttribute' is found doesn't necessarily mean
// it's a DEBUG build; we have to check the JIT Optimization flag
// i.e. it could have the "generate PDB" checked but have JIT Optimization enabled
DebuggableAttribute debuggableAttribute = attribs[0] as DebuggableAttribute;
if (debuggableAttribute != null)
{
HasDebuggableAttribute = true;
IsJITOptimized = !debuggableAttribute.IsJITOptimizerDisabled;
BuildType = debuggableAttribute.IsJITOptimizerDisabled ? "Debug" : "Release";
// check for Debug Output "full" or "pdb-only"
DebugOutput = (debuggableAttribute.DebuggingFlags &
DebuggableAttribute.DebuggingModes.Default) !=
DebuggableAttribute.DebuggingModes.None
? "Full" : "pdb-only";
}
}
else
{
IsJITOptimized = true;
BuildType = "Release";
}
Run Code Online (Sandbox Code Playgroud)
我在我的博客上提供了这个实现:
| 归档时间: |
|
| 查看次数: |
67865 次 |
| 最近记录: |