c# - How to load dlls from a NuGet into the current AppDomain? -
i try create modulable system in each module can depend on other ones. each module nuget , dependencies have resolved via nuget. each module contains type implements shared interface allow extracting list of instruction.
all these instructions executed in reverse order.
the detailed situation this:
i have 4 projects call
api
,s
,m1
,m2
. nugets , depends 1 way (->
stands 'depends on'):s -> api
,m1 -> s
,m2 -> m1
.on other hand have projet
core
,console
,tests
. aren't nugets references each others in way (->
stands 'references'):core -> s
,console -> core
,tests -> core
.m1 et m2 modules, once again special because contains type must found , instantiated within core.
the goal this:
i must fetch , install locally nugets given repository.
- this done, fetch nugets, unzip them given location.
i must inject dlls extraction installer if sort of plugins.
- how inject correct dlls imported nugets knowing that:
- some of them present in project
core
(notably dlls present in projectsapi
,s
). - some of them contain copies of dll different .net frameworks.
- when succeed inject dlls (by artificial processes of filtering
lib/whateverframework
directories , try find types have specific attribute (which located in shared projectapi
), attribute seems different if use 1 in dlls nuget , 1 can directly use in vs.
- some of them present in project
- how inject correct dlls imported nugets knowing that:
i use c# 6 , vs2015.
how load dlls running application all dependencies using nuget core api solve dependencies? best/proper way this?
a sample code use:
var localrepository = new sharedpackagerepository(packagespath); var allassemblies = localrepository .getpackages() .toarray() .selectmany(p => p.assemblyreferences.select(a => { var path = path.combine(packagespath, p.id + "." + p.version, a.path); var aname = assemblyname.getassemblyname(path); return new { key = aname.fullname, value = path }; })) .distinctby(i => i.key) .todictionary(i => i.key, => i.value); appdomain.currentdomain.assemblyresolve += (sender, eventargs) => { var aname = new assemblyname(eventargs.name); if (allassemblies.containskey(aname.fullname)) { return assembly.loadfile(allassemblies[aname.fullname]); } return null; };
Comments
Post a Comment