/// <summary> /// Add dependency information to a load context from a .deps.json file. /// </summary> /// <param name="builder">The builder.</param> /// <param name="depsFilePath">The full path to the .deps.json file.</param> /// <returns>The builder.</returns> public static AssemblyLoadContextBuilder AddDependencyContext(this AssemblyLoadContextBuilder builder, string depsFilePath) { var reader = new DependencyContextJsonReader(); using (var file = File.OpenRead(depsFilePath)) { var deps = reader.Read(file); builder.SetBaseDirectory(Path.GetDirectoryName(depsFilePath)); builder.AddDependencyContext(deps); } return(builder); }
/// <summary> /// Add dependency information to a load context from a .deps.json file. /// </summary> /// <param name="builder">The builder.</param> /// <param name="depsFilePath">The full path to the .deps.json file.</param> /// <param name="error">An error, if one occurs while reading .deps.json</param> /// <returns>The builder.</returns> public static AssemblyLoadContextBuilder TryAddDependencyContext(this AssemblyLoadContextBuilder builder, string depsFilePath, out Exception error) { error = null; try { builder.AddDependencyContext(depsFilePath); } catch (Exception ex) { error = ex; } return(builder); }