c# - How to read names and versions of assemblies -
i have create application read name of dlls (assemblies) in application path along version. , read same of dll in sub folders.
how in c#. can 1 me sample code?
edit : how read details of legacy dlls( external dlls- not created in .net)
thanks in advance.
you should search through given root directory calling directory.getfiles()
. can run through result , load every assembly calling assembly.reflectiononlyloadfrom()
(cause if load way won't added appdomain, thous no unload needed).
with these assembly
classes can access getname()
function , take version
property version information.
other properties, not get, can reached through getcustomattribute()
function this:
((assemblycopyrightattribute)assembly.getcustomattribute(typeof(assemblycopyrightattribute), true).copyright
with these informations should able built list like.
update:
and here's obligatory linq code sample:
var rootpath = @"c:\myroot\folder"; var query = directory.getfiles(rootpath, "*.dll", searchoption.alldirectories) .select(filename => { try { return assembly.reflectiononlyloadfrom(filename); } catch { return null; } }) .where(assembly => assembly != null) .select(assembly => new { version = assembly.getname().version.tostring(), name = assembly.getname().name }); foreach (var infos in query) { console.writeline(infos.name + " " + infos.version); }
update 2:
so normal dlls should take this question.
Comments
Post a Comment