IT박스

.NET 응용 프로그램의 종속성을 확인하려면 어떻게합니까?

itboxs 2020. 8. 19. 07:50
반응형

.NET 응용 프로그램의 종속성을 확인하려면 어떻게합니까?


.NET 응용 프로그램의 종속성을 확인하려면 어떻게합니까? Dependency Walker 는 관리되는 앱에서 작동 합니까 ? 최신 버전을 다운로드하고 앱 프로파일 링을 시도했지만 별다른 설명없이 종료됩니다. .NET에서 작동하지 않는 경우 런타임 DLL로드 문제를 디버깅하는 데 도움이되는 다른 도구가 있습니까?


종속성 워커는 일반 win32 바이너리에서 작동합니다. 모든 .NET dll과 exe는 일반 바이너리처럼 보이게하는 작은 스텁 헤더 부분을 가지고 있지만 기본적으로 "load the CLR"이라고 말하는 것입니다. 따라서 종속성 워커가 알려줄 모든 것입니다.

.NET 앱이 실제로 어떤 것에 의존하는지 확인하려면 Red Gate 의 엄청나게 뛰어난 .NET 리플렉터사용할 수 있습니다 . (편집 : .NET Reflector는 이제 유료 제품입니다. ILSpy 는 무료이며 오픈 소스이며 매우 유사합니다.)

DLL을로드하고 마우스 오른쪽 버튼을 클릭 한 다음 'Analyze'를 선택합니다. 그러면 필요한 다른 모든 dll (및 해당 dll 내부의 메서드)을 보여주는 "Depends On"항목이 표시됩니다.

하지만 앱이 X dll에 의존하고 X dll이 존재하지만 어떤 이유로 든 런타임에로드하거나 찾을 수 없다는 점에서 까다로울 수 있습니다.

이러한 종류의 문제를 해결하기 위해 Microsoft에는 런타임 에 무슨 일이 일어나고 있는지 보여줄 수 있는 어셈블리 바인딩 로그 뷰어 가 있습니다.


작은 유틸리티 AsmSpy 는 어셈블리로드 문제를 해결하는 데 매우 중요한 도구입니다. 어셈블리 버전을 포함하여 관리되는 어셈블리의 모든 어셈블리 참조를 나열합니다.

의 디렉터리에있는 명령 프롬프트에서 .dll다음 인수를 사용하여 실행합니다 .

asmspy . all

asmspy 출력 스크린 샷

Chocolatey로 빠르게 설치하십시오.

choco install asmspy

ILDASM에서 어셈블리 파일을 열고 MANIFEST에서 .assembly extern을 찾습니다.


.NET 코드 종속성을 검색하려면 NDepend 도구의 기능을 사용할 수 있습니다. 이 도구는 다음을 제안합니다.

예를 들어 이러한 쿼리는 다음과 같습니다.

from m in Methods 
let depth = m.DepthOfIsUsing("NHibernate.NHibernateUtil.Entity(Type)") 
where depth  >= 0 && m.IsUsing("System.IDisposable")
orderby depth
select new { m, depth }

그리고 그 결과는 다음과 같습니다. (코드 메트릭 깊이 , 1은 직접 호출자, 2는 직접 호출자를위한 것입니다 ...) (또한 쿼리 결과를 호출 그래프 로 내보내는 그래프로 내보내기 버튼에 유의하십시오 )

C # LINQ 쿼리를 통한 NDepend 종속성 검색

종속성 그래프는 다음과 같습니다.

NDepend 종속성 그래프

종속성 매트릭스는 다음과 같습니다.

NDepend 종속성 매트릭스

종속성 매트릭스는 사실상 그래프보다 덜 직관적이지만 다음과 같은 복잡한 코드 섹션을 탐색하는 데 더 적합합니다.

NDepend 매트릭스와 그래프

면책 조항 : 저는 NDepend에서 일합니다


셰어웨어 앱이나 도구를 다운로드하고 설치할 필요가 없습니다. .NET에서 프로그래밍 방식으로 수행 할 수 있습니다.Assembly.GetReferencedAssemblies()

Assembly.LoadFile(@"app").GetReferencedAssemblies()

If you are using the Mono toolchain, you can use the monodis utility with the --assemblyref argument to list the dependencies of a .NET assembly. This will work on both .exe and .dll files.

Example usage:

monodis --assemblyref somefile.exe

Example output (.exe):

$ monodis --assemblyref monop.exe
AssemblyRef Table
1: Version=4.0.0.0
    Name=System
    Flags=0x00000000
    Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89
2: Version=4.0.0.0
    Name=mscorlib
    Flags=0x00000000
    Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89

Example output (.dll):

$ monodis --assemblyref Mono.CSharp.dll
AssemblyRef Table
1: Version=4.0.0.0
    Name=mscorlib
    Flags=0x00000000
    Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89
2: Version=4.0.0.0
    Name=System.Core
    Flags=0x00000000
    Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89
3: Version=4.0.0.0
    Name=System
    Flags=0x00000000
    Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89
4: Version=4.0.0.0
    Name=System.Xml
    Flags=0x00000000
    Public Key:
0x00000000: B7 7A 5C 56 19 34 E0 89

Enable assembly binding logging set the registry value EnableLog in HKLM\Software\Microsoft\Fusion to 1. Note that you have to restart your application (use iisreset) for the changes to have any effect.

Tip: Remember to turn off fusion logging when you are done since there is a performance penalty to have it turned on.


It's funny I had a similar issue and didn't find anything suitable and was aware of good old Dependency Walker so in the end I wrote one myself.

This deals with .NET specifically and will show what references an assembly has (and missing) recursively. It'll also show native library dependencies.

It's free (for personal use) and available here for anyone interested: www.netdepends.com

www.netdepends.com

Feedback welcome.


http://www.amberfish.net/

ChkAsm will show you all the dependencies of a particular assembly at once, including the versions, and easily let you search for assemblies in the list. Works much better for this purpose than ILSpy (http://ilspy.net/), which is what I used to use for this task.


Another handy Reflector add-in that I use is the Dependency Structure Matrix. It's really great to see what classes use what. Plus it's free.


옵션을 사용하여 .NET 어셈블리를 컴파일 해보십시오 --staticlink:"Namespace.Assembly". 이렇게하면 컴파일러가 컴파일 타임에 모든 종속성을 가져옵니다. 참조되지 않은 종속성이 발견되면 일반적으로 해당 어셈블리의 이름과 함께 경고 또는 오류 메시지가 표시됩니다.

Namespace.Assembly종속성 문제가있는 것으로 의심되는 어셈블리입니다. 일반적으로이 어셈블리를 정적으로 연결하면 모든 종속성이 전 이적으로 참조됩니다.


내가보고 사용하는 최고의 앱, 누락 / 문제가있는 dll 표시 : http://www.dependencywalker.com/

참고 URL : https://stackoverflow.com/questions/227886/how-do-i-determine-the-dependencies-of-a-net-application

반응형