Ver*_*kso 6 c# build visual-studio-2010 .net-assembly visual-studio-2012
我正在使用VS2010/2012,我想知道是否有办法(可能使用反射)来查看程序集的构建方式.
当我在Debug中运行时,我使用将#if DEBUG
调试信息写入控制台.
但是,当你最终得到一堆程序集时,有没有办法看看它们是如何构建的?获取版本号很简单,但我无法找到如何检查构建类型.
有3种方法:
private bool IsAssemblyDebugBuild(string filepath)
{
return IsAssemblyDebugBuild(Assembly.LoadFile(Path.GetFullPath(filepath)));
}
private bool IsAssemblyDebugBuild(Assembly assembly)
{
foreach (var attribute in assembly.GetCustomAttributes(false))
{
var debuggableAttribute = attribute as DebuggableAttribute;
if(debuggableAttribute != null)
{
return debuggableAttribute.IsJITTrackingEnabled;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
或者使用 assemblyinfo 元数据:
#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Release")]
#endif
Run Code Online (Sandbox Code Playgroud)
#if DEBUG
或者在代码中使用常量
#if DEBUG
public const bool IsDebug = true;
#else
public const bool IsDebug = false;
#endif
Run Code Online (Sandbox Code Playgroud)
我更喜欢第二种方式,这样我就可以通过代码和 Windows 资源管理器来阅读它
归档时间: |
|
查看次数: |
393 次 |
最近记录: |