how to read the assembly manifest without loading

2020-07-15 02:45发布

Essentially need to read the dependencies programmatically without loading the assembly itself, as then you can't unload them

6条回答
Explosion°爆炸
2楼-- · 2020-07-15 03:14

Use DnSpy (it won't load the dll in your program):

        var assemblyDef = dnlib.DotNet.AssemblyDef.Load("myDllName.dll");
        var manifest = assemblyDef.ManifestModule; // do whatever you want from here

ref: https://www.nuget.org/packages/dnSpyLibs

I did a blog post on that: https://medium.com/angular-and-dot-net/reading-assembly-info-without-loading-it-in-c-31a4bea7ef73

查看更多
forever°为你锁心
3楼-- · 2020-07-15 03:15

found this System.Reflection.Assembly.ReflectionOnlyLoadFrom(path) does the trick

查看更多
▲ chillily
4楼-- · 2020-07-15 03:18

2 solutions come to my mind, although I think there's easier way (which I forgot or don't know :) ):
1. Load your assemblies using some additional AppDomain that you can create. Unloading whole AddDomain will also unload loaded assemblies (but only those, which were loaded using this AppDomain).
2. Use some api, for example CCI that allows you to look inside managed dll's without loading it using reflection mechanism.

查看更多
混吃等死
5楼-- · 2020-07-15 03:24

I'm sure someone will correct me if I'm wrong, but isn't the manifest just another resource in the DLL? If so, you can read it just like any other resource.

Here is an open source tool that lets you explore a DLLs resources:

http://www.wilsonc.demon.co.uk/d10resourceeditor.htm

And sure enough, I can see embedded manifests with it.

So, load the DLL using LoadLibrary() and go resource hunting.

查看更多
时光不老,我们不散
6楼-- · 2020-07-15 03:29

Kumar,

You CAN unload .Net DLLs but you have to use the AppDomain object to load them in the first place and then again to unload.

Take a look: http://msdn.microsoft.com/en-us/library/system.appdomain(VS.80).aspx

If you still want to avoid this type of process, i suppose you could parse the the DLL yourself but that would be much more work than using the AppDomain i think.

-p

查看更多
forever°为你锁心
7楼-- · 2020-07-15 03:29

Hope you are expecting Ildasm.exe (intermediate language disassembler)

http://msdn.microsoft.com/en-us/library/aa309387(VS.71).aspx

查看更多
登录 后发表回答