linux编译调试c程序_如何以编程方式检测程序集是否在调试或发布模式下编译

linux编译调试c程序

linux编译调试c程序

Nagaraj from my company made this little util recently to run against a compiled assembly and see if it is a Debug or Release version. I added the DOS ErrorLevel return codes.

我公司的Nagaraj最近制作了这个小工具,可以在已编译的程序集中运行,并查看它是Debug还是Release版本。 我添加了DOS ErrorLevel返回代码。

using System;

使用系统;

using System.IO;

使用System.IO;

using System.Diagnostics;

使用System.Diagnostics;

using System.Reflection;

使用System.Reflection;

namespace Foo.Tools

命名空间Foo.Tools

{

{

    class BuildFind

BuildFind类

    {

{

        public static int GetBuildType(string AssemblyName)

公共静态int GetBuildType(字符串AssemblyName)

        {

{

            Assembly assm = Assembly.LoadFrom(AssemblyName);

装配体=装配体.LoadFrom(AssemblyName);

            object[] attributes = assm.GetCustomAttributes(typeof(DebuggableAttribute), false);

对象[]属性= assm.GetCustomAttributes(typeof运算(DebuggableAttribute),假);

            if (attributes.Length == 0)

如果(attributes.Length == 0)

            {

{

                Console.WriteLine(String.Format("{0} is a RELEASE Build....", AssemblyName));

Console .WriteLine( String .Format( “ {0}是一个RELEASE Build ....” ,AssemblyName));

                return 0;

返回0;

            }

}

            foreach (Attribute attr in attributes)

的foreach(在属性属性ATTR)

            {

{

                if (attr is DebuggableAttribute)

如果(attr是DebuggableAttribute )

                {

{

                    DebuggableAttribute d = attr as DebuggableAttribute;

DebuggableAttribute d = attr作为DebuggableAttribute ;

                    Console.WriteLine(                       String.Format("Run time Optimizer is enabled : {0}", !d.IsJITOptimizerDisabled));

Console .WriteLine( String .Format( “运行时优化器已启用:{0}” ,!d.IsJITOptimizerDisabled));

                    Console.WriteLine(                        String.Format("Run time Tracking is enabled : {0}", d.IsJITTrackingEnabled));

Console .WriteLine( String .Format( “运行时跟踪已启用:{0}” ,d.IsJITTrackingEnabled));

                    if (d.IsJITOptimizerDisabled == true)

如果(d.IsJITOptimizerDisabled == true )

                    {

{

                        Console.WriteLine(String.Format("{0} is a DEBUG Build....", AssemblyName));

Console .WriteLine( String .Format( “ {0}是一个DEBUG Build ....” ,AssemblyName));

                        return 1;

返回1;

                    }

}

                    else

其他

                    {

{

                        Console.WriteLine(String.Format("{0} is a RELEASE Build....", AssemblyName));

Console .WriteLine( String .Format( “ {0}是一个RELEASE版本...。” ,AssemblyName));

                        return 0;

返回0;

                    }

}

                }

}

            }

}

            return 3;

返回3;

        }

}

        [STAThread]

[ STAThread ]

        static int Main(string[] args)

static int Main(字符串[] args)

        {

{

            if (args.Length == 0)

如果(args.Length == 0)

            {

{

                Console.WriteLine("Usage GetBuildType <assemblyName>");

Console .WriteLine( “用法GetBuildType <assemblyName>” );

                return 2;

返回2;

            }

}

            return BuildFind.GetBuildType(args[0]);

返回BuildFind .GetBuildType(args [0]);

        }

}

    }

}

}

}

翻译自: https://www.hanselman.com/blog/how-to-programmatically-detect-if-an-assembly-is-compiled-in-debug-or-release-mode

linux编译调试c程序

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值