private Library CreateLibrary(TargetLibrary targetLibrary, bool runtime, Dictionary <string, LibraryStub> libraryStubs) { var nameWithVersion = targetLibrary.Name; LibraryStub stub; if (libraryStubs == null || !libraryStubs.TryGetValue(nameWithVersion, out stub)) { throw new InvalidOperationException($"Cannot find library information for {nameWithVersion}"); } var seperatorPosition = nameWithVersion.IndexOf(DependencyContextStrings.VersionSeperator); var name = Pool(nameWithVersion.Substring(0, seperatorPosition)); var version = Pool(nameWithVersion.Substring(seperatorPosition + 1)); if (runtime) { // Runtime section of this library was trimmed by type:platform var isCompilationOnly = targetLibrary.CompileOnly; if (isCompilationOnly == true) { return(null); } var runtimeAssemblyGroups = new List <RuntimeAssetGroup>(); var nativeLibraryGroups = new List <RuntimeAssetGroup>(); if (targetLibrary.RuntimeTargets != null) { foreach (var ridGroup in targetLibrary.RuntimeTargets.GroupBy(e => e.Rid)) { var groupRuntimeAssemblies = ridGroup .Where(e => e.Type == DependencyContextStrings.RuntimeAssetType) .Select(e => e.Path) .ToArray(); if (groupRuntimeAssemblies.Any()) { runtimeAssemblyGroups.Add(new RuntimeAssetGroup( ridGroup.Key, groupRuntimeAssemblies.Where(a => Path.GetFileName(a) != "_._"))); } var groupNativeLibraries = ridGroup .Where(e => e.Type == DependencyContextStrings.NativeAssetType) .Select(e => e.Path) .ToArray(); if (groupNativeLibraries.Any()) { nativeLibraryGroups.Add(new RuntimeAssetGroup( ridGroup.Key, groupNativeLibraries.Where(a => Path.GetFileName(a) != "_._"))); } } } if (targetLibrary.Runtimes != null && targetLibrary.Runtimes.Count > 0) { runtimeAssemblyGroups.Add(new RuntimeAssetGroup(string.Empty, targetLibrary.Runtimes)); } if (targetLibrary.Natives != null && targetLibrary.Natives.Count > 0) { nativeLibraryGroups.Add(new RuntimeAssetGroup(string.Empty, targetLibrary.Natives)); } return(new RuntimeLibrary( type: stub.Type, name: name, version: version, hash: stub.Hash, runtimeAssemblyGroups: runtimeAssemblyGroups, nativeLibraryGroups: nativeLibraryGroups, resourceAssemblies: targetLibrary.Resources ?? Enumerable.Empty <ResourceAssembly>(), dependencies: targetLibrary.Dependencies, serviceable: stub.Serviceable, path: stub.Path, hashPath: stub.HashPath)); } else { var assemblies = (targetLibrary.Compilations != null) ? targetLibrary.Compilations : Enumerable.Empty <string>(); return(new CompilationLibrary( stub.Type, name, version, stub.Hash, assemblies, targetLibrary.Dependencies, stub.Serviceable, stub.Path, stub.HashPath)); } }
private Library?CreateLibrary(TargetLibrary targetLibrary, bool runtime, Dictionary <string, LibraryStub>?libraryStubs) { string nameWithVersion = targetLibrary.Name; if (libraryStubs == null || !libraryStubs.TryGetValue(nameWithVersion, out LibraryStub stub)) { throw new InvalidOperationException(SR.Format(SR.LibraryInformationNotFound, nameWithVersion)); } int separatorPosition = nameWithVersion.IndexOf(DependencyContextStrings.VersionSeparator); string name = Pool(nameWithVersion.Substring(0, separatorPosition)); string version = Pool(nameWithVersion.Substring(separatorPosition + 1)); if (runtime) { // Runtime section of this library was trimmed by type:platform bool?isCompilationOnly = targetLibrary.CompileOnly; if (isCompilationOnly == true) { return(null); } var runtimeAssemblyGroups = new List <RuntimeAssetGroup>(); var nativeLibraryGroups = new List <RuntimeAssetGroup>(); if (targetLibrary.RuntimeTargets != null) { foreach (IGrouping <string?, RuntimeTargetEntryStub> ridGroup in targetLibrary.RuntimeTargets.GroupBy(e => e.Rid)) { RuntimeFile[] groupRuntimeAssemblies = ridGroup .Where(e => e.Type == DependencyContextStrings.RuntimeAssetType) .Select(e => new RuntimeFile(e.Path, e.AssemblyVersion, e.FileVersion)) .ToArray(); if (groupRuntimeAssemblies.Any()) { runtimeAssemblyGroups.Add(new RuntimeAssetGroup( ridGroup.Key, groupRuntimeAssemblies.Where(a => Path.GetFileName(a.Path) != "_._"))); } RuntimeFile[] groupNativeLibraries = ridGroup .Where(e => e.Type == DependencyContextStrings.NativeAssetType) .Select(e => new RuntimeFile(e.Path, e.AssemblyVersion, e.FileVersion)) .ToArray(); if (groupNativeLibraries.Any()) { nativeLibraryGroups.Add(new RuntimeAssetGroup( ridGroup.Key, groupNativeLibraries.Where(a => Path.GetFileName(a.Path) != "_._"))); } } } if (targetLibrary.Runtimes != null && targetLibrary.Runtimes.Count > 0) { runtimeAssemblyGroups.Add(new RuntimeAssetGroup(string.Empty, targetLibrary.Runtimes)); } if (targetLibrary.Natives != null && targetLibrary.Natives.Count > 0) { nativeLibraryGroups.Add(new RuntimeAssetGroup(string.Empty, targetLibrary.Natives)); } return(new RuntimeLibrary( type: stub.Type, name: name, version: version, hash: stub.Hash, runtimeAssemblyGroups: runtimeAssemblyGroups, nativeLibraryGroups: nativeLibraryGroups, resourceAssemblies: targetLibrary.Resources ?? Enumerable.Empty <ResourceAssembly>(), dependencies: targetLibrary.Dependencies, serviceable: stub.Serviceable, path: stub.Path, hashPath: stub.HashPath, runtimeStoreManifestName: stub.RuntimeStoreManifestName)); } else { IEnumerable <string> assemblies = targetLibrary.Compilations ?? Enumerable.Empty <string>(); return(new CompilationLibrary( stub.Type, name, version, stub.Hash, assemblies, targetLibrary.Dependencies, stub.Serviceable, stub.Path, stub.HashPath)); } }