Exemple #1
0
 public static void AddCompileDependencies(this AssemblyLoadContextBuilder builder, DependencyContext dependencyContext)
 {
     foreach (var library in dependencyContext.CompileLibraries.Where(cl => !dependencyContext.RuntimeLibraries.Any(rl => cl.Name.Equals(rl.Name))))
     {
         foreach (var libraryAssembly in library.Assemblies.Where(a => a.StartsWith("lib", StringComparison.OrdinalIgnoreCase)))
         {
             var managedLibrary = ManagedLibrary.CreateFromPackage(library.Name, library.Version, libraryAssembly);
             try
             {
                 builder.AddManagedLibrary(managedLibrary);
             }
             catch (Exception ex)
             {
                 Console.WriteLine(ex.Message);
             }
         }
     }
 }