Microsoft MVP성태의 닷넷 이야기
글쓴 사람
정성태 (techsharer at outlook.com)
홈페이지
첨부 파일

(시리즈 글이 3개 있습니다.)
.NET Framework: 299. 해당 어셈블리가 Debug 빌드인지, Release 빌드인지 알아내는 방법
; https://www.sysnet.pe.kr/2/0/1227

.NET Framework: 315. 해당 DLL이 Managed인지 / Unmanaged인지 확인하는 방법
; https://www.sysnet.pe.kr/2/0/1279

.NET Framework: 328. 해당 DLL이 Managed인지 / Unmanaged인지 확인하는 방법 - 두 번째 이야기
; https://www.sysnet.pe.kr/2/0/1296




해당 어셈블리가 Debug 빌드인지, Release 빌드인지 알아내는 방법

국내는 어떤지 모르겠지만, 해외의 경우에는 '서비스 중인 DLL'이 Debug 빌드된 것인지, Release 빌드된 것인지를 민감하게 여기는 경우가 있는 것 같습니다. 필요 없이 성능에 손해되는 DLL로 서비스할 이유는 없으니까요.

검색을 해보면, 생각보다 쉽게 방법을 찾을 수 있습니다.

How to tell if a .NET application was compiled in DEBUG or RELEASE mode?
; http://stackoverflow.com/questions/194616/how-to-tell-if-a-net-application-was-compiled-in-debug-or-release-mode

정리해 보면, 결국 컴파일 된 DLL이 Debug인지 Release인지는 Debuggable이라는 특성에 지정된 값으로만 확인을 할 수 있습니다. 아래는 .NET Reflector로 확인해 본 것입니다.

debug_or_release_1.png

답이 모두 나왔군요. 즉, 해당 DLL을 로드한 다음 assembly 레벨에 지정된 Debuggable 특성을 살펴보면 되는 것입니다. 그런데, 어떤 값을 봐야 하는 걸까요?

일단, Visual Studio에서 Debug 모드로 빌드한 DLL은 다음와 같은 특성을 포함하고 있었습니다.

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.DisableOptimizations |
                      DebuggableAttribute.DebuggingModes.EnableEditAndContinue |
                      DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints |
                      DebuggableAttribute.DebuggingModes.Default)]

반면, Release 모드로 빌드한 경우에는 결과가 다릅니다.

[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]

특성들을 보건데, 당연히 "DebuggableAttribute.DebuggingModes.DisableOptimizations" 옵션값이 중요합니다. 실제로, DebuggableAttribute 타입에 정의된 IsJITOptimizerDisabled 공용 속성도 다음과 같이 마이크로소프트에 의해서 코드 작성이 된 것을 볼 수 있습니다.

public bool IsJITOptimizerDisabled
{
    get
    {
        return ((this.m_debuggingModes & DebuggingModes.DisableOptimizations) != DebuggingModes.None);
    }
}

아래는, (DLL을 잠그지 않는) ReflectionOnly 버전으로 작성한 코드입니다.

static void Main(string[] args)
{
    Assembly asm = Assembly.ReflectionOnlyLoadFrom("ClassLibrary1.dll");

    foreach (var attr in asm.GetCustomAttributesData())
    {
        if (attr.Constructor.ReflectedType == typeof(DebuggableAttribute))
        {
            foreach (var arg in attr.ConstructorArguments)
            {
                if (arg.ArgumentType == typeof(System.Diagnostics.DebuggableAttribute.DebuggingModes))
                {
                    System.Diagnostics.DebuggableAttribute.DebuggingModes mode = (System.Diagnostics.DebuggableAttribute.DebuggingModes)arg.Value;

                    bool isDebug = mode.HasFlag(System.Diagnostics.DebuggableAttribute.DebuggingModes.DisableOptimizations);
                    Console.WriteLine(asm.FullName + " ==> " + isDebug);
                }
            }
        }
    }
}




[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]







[최초 등록일: ]
[최종 수정일: 8/12/2021]

Creative Commons License
이 저작물은 크리에이티브 커먼즈 코리아 저작자표시-비영리-변경금지 2.0 대한민국 라이센스에 따라 이용하실 수 있습니다.
by SeongTae Jeong, mailto:techsharer at outlook.com

비밀번호

댓글 작성자
 




... 121  122  123  124  125  126  127  128  129  130  131  132  133  [134]  135  ...
NoWriterDateCnt.TitleFile(s)
1704정성태7/2/201421617.NET Framework: 447. w3wp.exe AppPool 재생(recycle)하는 방법 정리
1703정성태7/2/201422463.NET Framework: 446. Assembly.Load를 이용해 GAC에 등록된 어셈블리를 로드하는 방법 [1]파일 다운로드1
1702정성태6/23/201422167Phone: 11. Xamarin.Forms - 2. XAML을 이용한 페이지 개발파일 다운로드1
1701정성태6/23/201434348개발 환경 구성: 229. .NET Reflector + Reflexil 도구를 이용해 DLL 코드 변경 [4]
1700정성태6/23/201421169VS.NET IDE: 89. Visual Studio에서 기본 제공되는 성능 프로파일 [2]
1699정성태6/22/201423972Phone: 10. Xamarin.Forms - 1. Forms 시작하기 [2]파일 다운로드1
1698정성태6/22/201425945.NET Framework: 445. [부연 설명] 쉬운 C# 코드를 어럽게 이해하기 [2]
1697정성태6/22/201421229VS.NET IDE: 88. Visual Studio에서 직접 컴파일하는 IL 언어 확장 도구 - IL Support
1696정성태6/22/201421043.NET Framework: 444. clojure와 C#을 통해 이해하는 Sequence와 Vector 형식의 차이점 [1]
1695정성태6/21/201420041개발 환경 구성: 228. PowerShell ISE에서 (입력 기능이 있는) 콘솔 응용 프로그램을 시작하는 방법
1694정성태6/21/201421179개발 환경 구성: 227. 닷넷 용 ClojureCLR 개발환경 설정
1693정성태6/20/201421505개발 환경 구성: 226. Clojure 언어의 윈도우 개발환경 설정
1692정성태6/19/201432108오류 유형: 231. Visual Studio 2013 한글 버전 설치 오류 - The form specified for the subject is not one supported or known by the specified trust provider
1691정성태6/18/201427330개발 환경 구성: 225. 유닉스 계열의 tail 명령어가 제공되는 PowerShell [1]
1690정성태6/18/201430125개발 환경 구성: 224. DirectShow 예제 구하는 방법 [3]
1689정성태6/18/201426916오류 유형: 230. C++ 가변 인자 사용시 va_start 파라미터 전달 방법 [2]
1688정성태6/15/201420555오류 유형: 229. 갤럭시 노트 3 환경에서 Xamarin 앱 배포 충돌
1687정성태6/15/201426537개발 환경 구성: 223. PowerShell로 Visual Studio 빌드 스크립트 작성파일 다운로드1
1686정성태6/12/201424260Windows: 96. 윈도우 8 - 그림 암호를 이용해 로그인 시 지연 현상을 해결하는 방법 [1]
1685정성태6/10/201430987.NET Framework: 443. 자바 8과 C#의 람다(Lambda) 지원에 대한 비교 [12]
1684정성태6/9/201441127.NET Framework: 442. C# - 시스템의 CPU 사용량 및 프로세스(EXE)의 CPU 사용량 알아내는 방법 [5]파일 다운로드1
1683정성태6/2/201420682오류 유형: 228. CLR4 보안 - yield 구문 내에서 SecurityCritical 메서드 사용 불가 [2]파일 다운로드1
1682정성태6/1/201425915.NET Framework: 441. .NET CLR4 보안 모델 - 3. CLR4 보안 모델에서의 APTCA 역할파일 다운로드2
1681정성태6/1/201421787.NET Framework: 440. .NET CLR4 보안 모델 - 2. 샌드박스(Sandbox)을 이용한 보안 [2]파일 다운로드1
1680정성태6/1/201421296.NET Framework: 439. .NET CLR4 보안 모델 - 1. "Security Level 2"란?파일 다운로드1
1679정성태5/31/201420406.NET Framework: 438. .NET CLR2 보안 모델에서의 APTCA 역할파일 다운로드1
... 121  122  123  124  125  126  127  128  129  130  131  132  133  [134]  135  ...