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:

  1. i have 4 projects call api, s, m1, m2. nugets , depends 1 way (-> stands 'depends on'): s -> api, m1 -> s, m2 -> m1.

  2. on other hand have projet core, console , tests. aren't nugets references each others in way (-> stands 'references'): core -> s, console -> core, tests -> core.

  3. m1 et m2 modules, once again special because contains type must found , instantiated within core.

the goal this:

  1. i must fetch , install locally nugets given repository.

    • this done, fetch nugets, unzip them given location.
  2. i must inject dlls extraction installer if sort of plugins.

    • how inject correct dlls imported nugets knowing that:
      1. some of them present in project core (notably dlls present in projects api , s).
      2. some of them contain copies of dll different .net frameworks.
      3. when succeed inject dlls (by artificial processes of filtering lib/whateverframework directories , try find types have specific attribute (which located in shared project api), attribute seems different if use 1 in dlls nuget , 1 can directly use in vs.

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

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -