public static IEnumerable <Assembly> DiscoverAssemblyParts(Assembly entryAssembly /*string entryPointAssemblyName*/) { //var entryAssembly = Assembly.Load(new AssemblyName(entryPointAssemblyName)); var context = DependencyContext.Load(entryAssembly); return(GetCandidateAssemblies(entryAssembly, context)); }
private static void FindDependency(Assembly assembly) { DependencyContext dependencyContext = DependencyContext.Load(assembly); if (dependencyContext != null) { foreach (var compilationLibrary in dependencyContext.CompileLibraries) { if (!DependencyDLL.ContainsKey(compilationLibrary.Name) && !AppDomain.CurrentDomain.GetAssemblies().Any(a => a.FullName.Split(',')[0] == compilationLibrary.Name)) { RuntimeLibrary library = dependencyContext.RuntimeLibraries.FirstOrDefault(runtime => runtime.Name == compilationLibrary.Name); var cb = new CompilationLibrary( library.Type, library.Name, library.Version, library.Hash, library.RuntimeAssemblyGroups.SelectMany(g => g.AssetPaths), library.Dependencies, library.Serviceable); DependencyDLL[library.Name] = cb; } } } }
public static Assembly CreateAssemblyLoader(string path) { //this.folderPath = folderPath; var this1 = new AssemblyLoader(); var asm = this1.LoadFromAssemblyPath(path); //var applicationAssembly = Assembly.Load(new AssemblyName(path)); var context = DependencyContext.Load(asm); if (context != null) { for (var i = 0; i < context.CompileLibraries.Count; i++) { var library = context.CompileLibraries[i]; IEnumerable <string> referencePaths; try { referencePaths = library.ResolveReferencePaths(); } catch (InvalidOperationException e) { continue; } //add the references dlls.AddRange(referencePaths); } } //dlls = this1.dlls; return(asm); }
internal Assembly InternalLoad(string assemblyPath) { Assembly assembly = null; try { assembly = Assembly.LoadFile(assemblyPath); AssemblyName[] refAssemblies; var dps = DependencyContext.Default; //try resolve dependencies if (assembly != null) { DependencyContext.Load(assembly); refAssemblies = assembly.GetReferencedAssemblies(); foreach (var asm in refAssemblies.Where(n => n.FullName.Contains("ITSolution.Framework.Core") || n.FullName.Contains("ITSolution.Framework.Server.Core"))) { this.Load(asm); } } } catch (Exception ex) { Console.WriteLine("Não foi possível carregar o assembly especificado: '{0}' \n Exception: '{1}' \n '{2}'", assemblyPath, ex.Message, ex.StackTrace); } return(assembly); }
public BuildContext LoadAssemblyAndContext(BuildContext context) { var asm = Assembly.LoadFile(context.ResultingAssemblyFile); var dp = DependencyContext.Load(asm); var packageDirs = ((string)AppDomain.CurrentDomain.GetData("PROBING_DIRECTORIES")).Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); AssemblyLoadContext.Default.Resolving += (ctx, name) => { var depInfo = dp.RuntimeLibraries.FirstOrDefault(x => x.Name == name.Name); if (depInfo.Type == "package") { var loockupFolder = packageDirs.First(); var packageFolder = depInfo.Path; var fileName = depInfo.RuntimeAssemblyGroups[0].AssetPaths[0]; var fullPath = Path.Combine(loockupFolder, packageFolder, fileName); return(Assembly.LoadFile(fullPath)); } return(null); }; context.ResultingAssembly = asm; return(context); }
public DependencyResolver(string path) { try { Log($"Image base path is {Path.GetDirectoryName(path)}"); Assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(path); _dependencyContext = DependencyContext.Load(Assembly); _assemblyResolver = new CompositeCompilationAssemblyResolver (new ICompilationAssemblyResolver[] { new AppBaseCompilationAssemblyResolver(Path.GetDirectoryName(path)), new ReferenceAssemblyPathResolver(), new DependencyModel.Resolution.PackageCompilationAssemblyResolver() }); _loadContext = AssemblyLoadContext.GetLoadContext(Assembly); _loadContext.Resolving += OnResolving; } catch (Exception ex) { Log($"AssemblyResolver error: {ex}"); } }
public DefaultAssemblyProvider(IHostingEnvironment env) { var entryPointAssemblyName = env.ApplicationName; _entryAssembly = Assembly.Load(new AssemblyName(entryPointAssemblyName)); _dependencyContext = DependencyContext.Load(Assembly.Load(new AssemblyName(entryPointAssemblyName))); }
private Assembly LoadAssembly(string path) { if (this.assembliesByPath.ContainsKey(path)) { return(this.assembliesByPath[path]); } var loadContext = AssemblyLoadContext.GetLoadContext(this.GetType().GetTypeInfo().Assembly); var assembly = loadContext.LoadFromAssemblyPath(path); var newDependencyContext = DependencyContext.Load(assembly); if (newDependencyContext != null) { this.dependencyContext = this.dependencyContext.Merge(newDependencyContext); } var basePath = Path.GetDirectoryName(path); if (!this.directoriesWithResolver.Contains(basePath)) { this.assemblyResolver = new CompositeCompilationAssemblyResolver(new ICompilationAssemblyResolver[] { new AppBaseCompilationAssemblyResolver(basePath), this.assemblyResolver, }); this.directoriesWithResolver.Add(basePath); } this.assembliesByPath.Add(path, assembly); return(assembly); }
/// <summary> /// Create a project using the inputted strings as sources. /// </summary> /// <param name="sources">Classes in the form of strings</param> /// <returns>A Project created out of the Documents created from the source strings</returns> protected Project CreateProject(params string[] sources) { var fileNamePrefix = DefaultFilePathPrefix; var projectId = ProjectId.CreateNewId(debugName: TestProjectName); Solution = Solution ?? new AdhocWorkspace().CurrentSolution; Solution = Solution.AddProject(projectId, TestProjectName, TestProjectName, LanguageNames.CSharp) .WithProjectCompilationOptions(projectId, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); foreach (var defaultCompileLibrary in DependencyContext.Load(GetType().Assembly).CompileLibraries) { foreach (var resolveReferencePath in defaultCompileLibrary.ResolveReferencePaths(new AppLocalResolver())) { Solution = Solution.AddMetadataReference(projectId, MetadataReference.CreateFromFile(resolveReferencePath)); } } var count = 0; foreach (var source in sources) { var newFileName = fileNamePrefix + count; _testOutputHelper?.WriteLine("Adding file: " + newFileName + Environment.NewLine + source); var documentId = DocumentId.CreateNewId(projectId, debugName: newFileName); Solution = Solution.AddDocument(documentId, newFileName, SourceText.From(source)); count++; } return(Solution.GetProject(projectId)); }
private Project CreateProject(string source) { const string fileName = "Test.cs"; source = $@"using Microsoft.EntityFrameworkCore;using System.Data.SqlClient;class C {{ void M() {{ {source} }} }}"; //Debugger.Launch(); var projectId = ProjectId.CreateNewId(debugName: "TestProject"); var documentId = DocumentId.CreateNewId(projectId, fileName); var metadataReferences = DependencyContext.Load(GetType().Assembly) .CompileLibraries .SelectMany(c => c.ResolveReferencePaths()) .Select(path => MetadataReference.CreateFromFile(path)) .Cast <MetadataReference>() .ToList(); var solution = new AdhocWorkspace() .CurrentSolution .AddProject(projectId, "TestProject", "TestProject", LanguageNames.CSharp) .AddMetadataReferences(projectId, metadataReferences) .AddDocument(documentId, fileName, SourceText.From(source)); return(solution.GetProject(projectId) .WithCompilationOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary))); }
private void ResolveDenpendency() { string currentName = CurrentAssembly.GetName().Name; var dependencyCompilationLibrary = DependencyContext.Load(CurrentAssembly) .CompileLibraries.Where(de => de.Name != currentName && !DependencyContext.Default.CompileLibraries.Any(m => m.Name == de.Name)) .ToList(); dependencyCompilationLibrary.Each(libaray => { bool depLoaded = false; var files = new DirectoryInfo(Path.GetDirectoryName(CurrentAssembly.Location)).GetFiles($"{libaray.Name}.dll"); foreach (var file in files) { Console.WriteLine(file.FullName); DependencyAssemblies.Add(LoadFromAssemblyPath(file.FullName)); depLoaded = true; break; } if (!depLoaded) { foreach (var item in libaray.ResolveReferencePaths()) { if (File.Exists(item)) { DependencyAssemblies.Add(LoadFromAssemblyPath(item)); break; } } } }); }
/// <summary> /// Create a project using the inputted strings as sources. /// </summary> /// <param name="sources">Classes in the form of strings</param> /// <returns>A Project created out of the Documents created from the source strings</returns> private static Project CreateProject(string[] sources) { string fileNamePrefix = DefaultFilePathPrefix; var projectId = ProjectId.CreateNewId(debugName: TestProjectName); var solution = new AdhocWorkspace() .CurrentSolution .AddProject(projectId, TestProjectName, TestProjectName, LanguageNames.CSharp); foreach (var defaultCompileLibrary in DependencyContext.Load(typeof(DiagnosticVerifier).Assembly).CompileLibraries) { foreach (var resolveReferencePath in defaultCompileLibrary.ResolveReferencePaths(new AppLocalResolver())) { solution = solution.AddMetadataReference(projectId, MetadataReference.CreateFromFile(resolveReferencePath)); } } int count = 0; foreach (var source in sources) { var newFileName = fileNamePrefix + count; var documentId = DocumentId.CreateNewId(projectId, debugName: newFileName); solution = solution.AddDocument(documentId, newFileName, SourceText.From(source)); count++; } return(solution.GetProject(projectId)); }
protected Project CreateProject(string source) { var projectId = ProjectId.CreateNewId(debugName: "TestProject"); var newFileName = "Test.cs"; var documentId = DocumentId.CreateNewId(projectId, debugName: newFileName); var metadataReferences = DependencyContext.Load(GetType().Assembly) .CompileLibraries .SelectMany(c => c.ResolveReferencePaths()) .Select(path => MetadataReference.CreateFromFile(path)) .Cast <MetadataReference>() .ToList(); lock (WorkspaceLock) { if (Workspace == null) { Workspace = new AdhocWorkspace(); } } var solution = Workspace .CurrentSolution .AddProject(projectId, "TestProject", "TestProject", LanguageNames.CSharp) .AddMetadataReferences(projectId, metadataReferences) .AddDocument(documentId, newFileName, SourceText.From(source)); return(solution.GetProject(projectId)); }
/// <summary> /// 获取所有可能提供服务的对象 /// </summary> /// <returns></returns> private IEnumerable <Type> GetExportedTypes() { List <Assembly> assemblies = new List <Assembly>(); Assembly entryAssembly; if (null != _environment && !string.IsNullOrWhiteSpace(_environment.ApplicationName)) { entryAssembly = Assembly.Load(new AssemblyName(_environment.ApplicationName)); } else { entryAssembly = Assembly.GetEntryAssembly(); } var dependencies = DependencyContext.Load(entryAssembly).RuntimeLibraries; foreach (var library in dependencies) { if (!Ignore_Library_Regex.IsMatch(library.Name)) { var assembly = Assembly.Load(new AssemblyName(library.Name)); if (assembly.IsDynamic) { continue; } assemblies.Add(assembly); } } return(assemblies.SelectMany(item => item.GetExportedTypes())); }
public static BuildReference ByName(string name, bool copyLocal = false, Assembly depContextAssembly = null) { #if NETSTANDARD1_6 var depContext = depContextAssembly == null ? DefaultDependencyContext : DependencyContext.Load(depContextAssembly); if (depContext != null) { var library = depContext .CompileLibraries .FirstOrDefault(l => l.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (library != null) { return(new BuildReference( library.ResolveReferencePaths().Select(file => MetadataReference.CreateFromFile(file)), copyLocal)); } } #else var assembly = Assembly.Load(name); if (!string.IsNullOrEmpty(assembly.Location)) { return(new BuildReference( new[] { MetadataReference.CreateFromFile(assembly.Location) }, copyLocal, new Uri(assembly.CodeBase).LocalPath)); } #endif throw new InvalidOperationException( $"Assembly '{name}' not found."); }
public static Project Create(Assembly testAssembly, string[] sources) { var fileNamePrefix = DefaultFilePathPrefix; var projectId = ProjectId.CreateNewId(debugName: TestProjectName); var solution = new AdhocWorkspace() .CurrentSolution .AddProject(projectId, TestProjectName, TestProjectName, LanguageNames.CSharp); foreach (var defaultCompileLibrary in DependencyContext.Load(testAssembly).CompileLibraries) { foreach (var resolveReferencePath in defaultCompileLibrary.ResolveReferencePaths(new AppLocalResolver())) { solution = solution.AddMetadataReference(projectId, MetadataReference.CreateFromFile(resolveReferencePath)); } } for (var i = 0; i < sources.Length; i++) { var newFileName = fileNamePrefix; if (sources.Length > 1) { newFileName += i; } newFileName += ".cs"; var documentId = DocumentId.CreateNewId(projectId, debugName: newFileName); solution = solution.AddDocument(documentId, newFileName, SourceText.From(sources[i])); } return(solution.GetProject(projectId)); }
public static IEnumerable <Assembly> GetMessageCandidateAssemblies(params string[] tagAssemblies) { if (tagAssemblies == null) { throw new ArgumentNullException(nameof(tagAssemblies)); } if (tagAssemblies.Length == 0) { throw new ArgumentException("At least one tag assembly name must be specified.", nameof(tagAssemblies)); } var referenceAssemblies = new HashSet <string>(tagAssemblies, StringComparer.OrdinalIgnoreCase); #if NETCOREAPP var context = DependencyContext.Load(Assembly.GetEntryAssembly()); var loadContext = AssemblyLoadContext.Default; return(context.RuntimeLibraries .Where(x => x.Dependencies.Any(d => referenceAssemblies.Contains(d.Name))) .SelectMany(x => x.GetDefaultAssemblyNames(context)) .Select(loadContext.LoadFromAssemblyName)); #elif NETFRAMEWORK var context = DependencyContext.Load(Assembly.GetEntryAssembly()); return(context.RuntimeLibraries .Where(x => x.Dependencies.Any(d => referenceAssemblies.Contains(d.Name))) .SelectMany(x => x.GetDefaultAssemblyNames(context)) .Select(Assembly.Load)); #else throw new PlatformNotSupportedException(); #endif }
internal static IEnumerable <Assembly> DiscoverAssemblies(string entryPointAssemblyName) { var entryAssembly = Assembly.Load(new AssemblyName(entryPointAssemblyName)); var context = DependencyContext.Load(Assembly.Load(new AssemblyName(entryPointAssemblyName))); return(GetCandidateAssemblies(entryAssembly, context)); }
/// <summary> /// Adds the Dependency <paramref name="assembly"/> to the <see cref="Context"/> /// provided it has not already been Added. Also Initializes <see cref="Context"/> /// in the event it has not yet seen an <paramref name="assembly"/> Dependency. /// </summary> /// <param name="path"></param> /// <param name="assembly"></param> /// <returns>Returns the Dependency Context instance.</returns> /// <exception cref="CodeGenerationDependencyException"> /// Thrown when <paramref name="path"/> <see cref="DependencyContext"/> cannot be loaded. /// </exception> internal CompilationAssemblyResolverDependencyContext AddDependency(string path, Assembly assembly) { Requires.NotNull(assembly, nameof(assembly)); bool DoesHaveLibrary <TLibrary>(TLibrary x) where TLibrary : Library => HasLibrary(x, path); // ReSharper disable once InvertIf if (!(Context.CompileLibraries.Any(DoesHaveLibrary) || Context.RuntimeLibraries.Any(DoesHaveLibrary))) { try { // TODO: TBD: falling over, apparently, for reasons related to: // TODO: TBD: Improve task DLL load behavior / https://github.com/microsoft/msbuild/issues/1312 // TODO: TBD: the current suspicion is that `identifying´ references is insufficient... // TODO: TBD: we may need to actually attempt to load those `additional´ references. // TODO: TBD: what we do not want to end up doing, if we can avoid it, is loading a swath of Dot Net, or System, assemblies, if we can at all help it... // ReSharper disable once IdentifierTypo var assyDependencyContext = DependencyContext.Load(assembly); Requires.NotNull(assyDependencyContext, nameof(assyDependencyContext)); Context = Context.Merge(assyDependencyContext); } catch (Exception ex) { throw new CodeGenerationDependencyException($"Unable to load dependency `{path}´.", path, ex); } OnDependencyAdded(Context, path, assembly); } return(this); }
public void FindsAssembliesInCandidates_Enumerable() { var resolver = new DependencyContextAssemblyCandidateFinder( DependencyContext.Load(typeof(DependencyContextAssemblyCandidateFinderTests).GetTypeInfo().Assembly), Logger ); var items = resolver.GetCandidateAssemblies( new[] { "Rocket.Surgery.Conventions", "Rocket.Surgery.Conventions.Abstractions" }.AsEnumerable() ) .Select(x => x.GetName().Name) .ToArray(); foreach (var item in items) { Logger.LogInformation(item); } items .Should() .Contain( new[] { "Sample.DependencyOne", "Sample.DependencyTwo", "Sample.DependencyThree", "Rocket.Surgery.Conventions.Tests" } ); items .Last() .Should() .Be("Rocket.Surgery.Conventions.Tests"); }
public override void Configure(IFunctionsHostBuilder builder) { builder.Services.Configure <MyConfiguration>(Configuration.GetSection("MyConfiguration")); builder.Services.Configure <MyConfiguration>(Configuration.GetSection("MyConfigurationSecrets")); builder.Services.Configure <Serilog>(Configuration.GetSection("Serilog")); //var logger = new LoggerConfiguration() //.ReadFrom.Configuration(Configuration) //.CreateLogger(); //SelfLog.Enable(msg => Debug.WriteLine(msg)); //builder.Services.AddLogging(lg => //{ // lg.AddSerilog(logger); // SelfLog.Enable(Console.Error); //}); builder.Services.AddScoped <IOrder, Order>(); builder.Services.AddScoped <IProduct, Product>(); builder.Services.AddSingleton <ILoggerProvider>(sp => { var functionDependencyContext = DependencyContext.Load(typeof(Startup).Assembly); var hostConfig = sp.GetRequiredService <IConfiguration>(); var logger = new LoggerConfiguration() .ReadFrom.Configuration(hostConfig, sectionName: "AzureFunctionsJobHost:Serilog", dependencyContext: functionDependencyContext) .CreateLogger(); return(new SerilogLoggerProvider(logger, true)); }); }
/// <summary> /// Run the discovery routine using the provided ruleset. /// </summary> /// <param name="mvcBuilder">The application IMvcBuilder configuration.</param> /// <param name="rules">The ruleset to use when discovering assemblies.</param> /// <returns> /// A collection of additional assemblies to reference that aren't already referenced /// by the IMvcBuilder AssemblyPartsProvider. /// </returns> public IEnumerable <Assembly> DiscoverAssemblies( IMvcBuilder mvcBuilder, IEnumerable <IAssemblyDiscoveryRule> rules ) { var environment = GetServiceFromCollection <IHostingEnvironment>(mvcBuilder.Services); if (string.IsNullOrEmpty(environment?.ApplicationName)) { return(Enumerable.Empty <Assembly>()); } var entryAssembly = Assembly.Load(new AssemblyName(environment.ApplicationName)); var dependencyContext = DependencyContext.Load(entryAssembly); if (dependencyContext == null) { return(Enumerable.Empty <Assembly>()); } var existingReferences = mvcBuilder .PartManager .ApplicationParts .OfType <AssemblyPart>() .ToDictionary(p => p.Name, StringComparer.OrdinalIgnoreCase); var additionalAssemblies = LoadAdditionalApplicationParts( entryAssembly, dependencyContext, existingReferences, rules); return(additionalAssemblies); }
public static IEnumerable <ApplicationPart> DiscoverAssemblyParts(string entryPointAssemblyName) { var entryAssembly = Assembly.Load(new AssemblyName(entryPointAssemblyName)); var context = DependencyContext.Load(Assembly.Load(new AssemblyName(entryPointAssemblyName))); return(GetCandidateAssemblies(entryAssembly, context).Select(p => new AssemblyPart(p))); }
private string GetPre30CoreFrameworkVersion() { #if !NET461 // Try and get version directly from AppContext data var fxProductVersion = AppContext.GetData("FX_PRODUCT_VERSION") as string; if (!string.IsNullOrEmpty(fxProductVersion)) { return(fxProductVersion); } // Try and parse version from shared framework folder var fxDepsFile = AppContext.GetData("FX_DEPS_FILE") as string; if (!string.IsNullOrEmpty(fxDepsFile)) { try { var frameworkDirPath = Path.GetDirectoryName(fxDepsFile); return(GetSharedFrameworkVersion(frameworkDirPath)); } catch (Exception) { } // Fallback to just getting version from dependency context var appAssembly = Assembly.Load(new AssemblyName(_env.ApplicationName)); return(DependencyContext.Load(appAssembly) .RuntimeLibraries .FirstOrDefault(l => string.Equals(l.Name, "Microsoft.NETCore.App", StringComparison.OrdinalIgnoreCase)) .Version); } #endif return(null); }
public void Builder_Should_Create_Host_ByDependencyContext() { Action a = () => ConventionTestHostBuilder.For(DependencyContext.Load(GetType().Assembly), LoggerFactory) .Create(); a.Should().NotThrow(); }
public void PopulateFeature( IEnumerable <ApplicationPart> parts, MetadataReferenceFeature feature) { HashSet <string> libraryPaths = new HashSet <string>(StringComparer.OrdinalIgnoreCase); foreach (var assemblyPart in parts.OfType <AssemblyPart>()) { DependencyContext dependencyContext = DependencyContext .Load(assemblyPart.Assembly); if (dependencyContext != null) { foreach (CompilationLibrary library in dependencyContext.CompileLibraries) { if ("reference".Equals(library.Type, StringComparison.OrdinalIgnoreCase)) { foreach (var libraryAssembly in library.Assemblies) { libraryPaths.Add( Path.Combine( AppDomain.CurrentDomain.BaseDirectory, libraryAssembly ) ); } } else { // TODO: optimize try { foreach (string path in library.ResolveReferencePaths()) { libraryPaths.Add(path); } } catch (Exception) { libraryPaths.Add(assemblyPart.Assembly.Location); } } } } else { libraryPaths.Add(assemblyPart.Assembly.Location); } } foreach (var path in libraryPaths) { feature.MetadataReferences.Add(CreateMetadataReference(path)); } }
public DefaultAssemblyProvider() { var entryAssembly = Assembly.GetEntryAssembly(); var dependencyModel = DependencyContext.Load(entryAssembly); var assemblyNames = dependencyModel.GetRuntimeAssemblyNames(RuntimeEnvironment.GetRuntimeIdentifier()); AvailableAssemblies = assemblyNames.Select(asm => new AssemblyInfo(asm.Name, string.Empty)); }
public DependencyContextResolutionTests() { IServiceCollection services = new ServiceCollection(); services.AddSingleton(new Logger()); services.AddMediatR(DependencyContext.Load(typeof(DependencyContextResolutionTests).GetTypeInfo().Assembly)); _provider = services.BuildServiceProvider(); }
/// <summary> /// Returns assemblies /// </summary> /// <returns></returns> public IReadOnlyCollection <Assembly> GetAssemblies() { var entryAssembly = Assembly.GetEntryAssembly(); var dependencyContext = DependencyContext.Load(entryAssembly); var names = dependencyContext.GetDefaultAssemblyNames(); return(names.Select(info => Assembly.Load(new AssemblyName(info.Name))).ToArray()); }
public AssemblyResolver(string path, List <string> referencedAssemblies, bool installDefaultResolveHandler = true) { this.installDefaultResolveHandler = installDefaultResolveHandler; if (Path.GetFileName(path) == "Orleans.Core.dll") { this.Assembly = typeof(RuntimeVersion).Assembly; } else { this.Assembly = Assembly.LoadFrom(path); } this.dependencyContext = DependencyContext.Load(this.Assembly); this.resolverRependencyContext = DependencyContext.Load(typeof(AssemblyResolver).Assembly); var codegenPath = Path.GetDirectoryName(new Uri(typeof(AssemblyResolver).Assembly.CodeBase).LocalPath); this.assemblyResolver = new CompositeCompilationAssemblyResolver( new ICompilationAssemblyResolver[] { new AppBaseCompilationAssemblyResolver(codegenPath), new AppBaseCompilationAssemblyResolver(Path.GetDirectoryName(path)), new ReferenceAssemblyPathResolver(), new PackageCompilationAssemblyResolver() }); #if NETCOREAPP this.loadContext = AssemblyLoadContext.GetLoadContext(this.Assembly); if (this.loadContext == AssemblyLoadContext.Default) { if (this.installDefaultResolveHandler) { AssemblyLoadContext.Default.Resolving += this.AssemblyLoadContextResolving; } } else { this.loadContext.Resolving += this.AssemblyLoadContextResolving; } #else if (this.installDefaultResolveHandler) { AppDomain.CurrentDomain.AssemblyResolve += this.ResolveAssembly; } #endif foreach (var assemblyPath in referencedAssemblies) { var libName = Path.GetFileNameWithoutExtension(assemblyPath); if (!string.IsNullOrWhiteSpace(libName)) { this.ReferenceAssemblyPaths[libName] = assemblyPath; } var asmName = AssemblyName.GetAssemblyName(assemblyPath); this.ReferenceAssemblyPaths[asmName.FullName] = assemblyPath; } }