diff --git a/src/Microsoft.DotNet.ProjectModel/DependencyContextBuilder.cs b/src/Microsoft.DotNet.ProjectModel/DependencyContextBuilder.cs index a70cedffd..de5cd3394 100644 --- a/src/Microsoft.DotNet.ProjectModel/DependencyContextBuilder.cs +++ b/src/Microsoft.DotNet.ProjectModel/DependencyContextBuilder.cs @@ -68,8 +68,12 @@ namespace Microsoft.Extensions.DependencyModel var libraryAssets = runtime ? export.RuntimeAssemblies : export.CompilationAssemblies; - foreach (var libraryDependency in export.Library.Dependencies) + foreach (var libraryDependenciesGroup in export.Library.Dependencies.GroupBy(d => d.Name)) { + LibraryRange libraryDependency = libraryDependenciesGroup + .OrderByDescending(d => d.Target == LibraryType.ReferenceAssembly) + .First(); + Dependency dependency; if (dependencyLookup.TryGetValue(libraryDependency.Name, out dependency)) { diff --git a/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs b/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs index 6f73ef6b5..d1f06201c 100644 --- a/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs +++ b/src/Microsoft.Extensions.DependencyModel/DependencyContext.cs @@ -38,7 +38,12 @@ namespace Microsoft.Extensions.DependencyModel private static DependencyContext LoadDefault() { var entryAssembly = Assembly.GetEntryAssembly(); - var stream = entryAssembly?.GetManifestResourceStream(entryAssembly.GetName().Name + DepsResourceSufix); + return Load(entryAssembly); + } + + public static DependencyContext Load(Assembly assembly) + { + var stream = assembly.GetManifestResourceStream(assembly.GetName().Name + DepsResourceSufix); if (stream == null) {