public void Replace(string what, LoadedPackage with) { foreach (var g in Values) { g.Replace(what, with); } }
public void Replace(string what, LoadedPackage package) { var dep = _list.FirstOrDefault(d => d.Id == what); if (dep == null) { return; } var newDep = new BinaryDependency(dep, package); _list.Remove(dep); Add(newDep); }
public void MergeContents(INumergeLogger logger, LoadedPackage victim, PackageMergeConfiguration config) { var ignoredPrefixes = new[] { "lib/", "_rels/", "package/" }; foreach (var item in victim.BinaryContents.Where(x => x.Key.Contains("/") && !ignoredPrefixes.Any(p => x.Key.StartsWith(p)))) { if (BinaryContents.ContainsKey(item.Key)) { logger.Warning($"{Spec.Id}: Refusing to replace item {item.Key} with item from {victim.Spec.Id}"); } else { BinaryContents[item.Key] = item.Value; } } var libs = victim.BinaryContents.Where(x => x.Key.StartsWith("lib/")) .Select(x => new { sp = x.Key.Split(new[] { '/' }, 3), data = x.Value }) .Select(x => new { Tfm = x.sp[1], File = x.sp[2], Data = x.data }).GroupBy(x => x.Tfm) .ToDictionary(x => x.Key, x => x.ToList()); var ourFrameworks = BinaryContents.Where(x => x.Key.StartsWith("lib/")).Select(x => x.Key.Split('/')[1]) .Distinct().ToList(); foreach (var foreignTfm in libs) { if (!ourFrameworks.Contains(foreignTfm.Key)) { throw new MergeAbortedException( $"Error merging {victim.Spec.Id}: Package {Spec.Id} doesn't have target framework {foreignTfm.Key}"); } } //TODO: Actually detect compatibility with .NET Standard libs.TryGetValue("netstandard2.0", out var netstandardLibs); foreach (var framework in ourFrameworks) { libs.TryGetValue(framework, out var frameworkLibs); frameworkLibs = frameworkLibs ?? netstandardLibs; if (frameworkLibs == null) { if (!config.IgnoreMissingFrameworkBinaries) { throw new MergeAbortedException( $"Unable to merge {victim.Spec.Id} to {Spec.Id}: {victim.Spec.Id} doesn't support {framework} or netstandard2.0"); } } else { foreach (var lib in frameworkLibs) { var targetPath = $"lib/{framework}/{lib.File}"; if (BinaryContents.ContainsKey(targetPath)) { logger.Warning( $"{Spec.Id}: Refusing to replace item {targetPath} with item from {victim.Spec.Id}"); } else { BinaryContents[targetPath] = lib.Data; } } } } if (!config.DoNotMergeDependencies) { //TODO: Actually detect compatibility with .NET Standard if (!victim.Spec.Dependencies.TryGetValue(".NETStandard2.0", out var netstandardDeps)) { victim.Spec.Dependencies.TryGetValue("netstandard2.0", out netstandardDeps); } var handledDepFrameworks = new HashSet <string>(); foreach (var group in victim.Spec.Dependencies) { Spec.Dependencies.GetOrCreateGroup(group.Key) .AddRange(group.Value); handledDepFrameworks.Add(group.Key); } foreach (var ourGroup in Spec.Dependencies) { // Merge deps if (!handledDepFrameworks.Contains(ourGroup.Key)) { if (netstandardDeps == null) { if (!config.IgnoreMissingFrameworkDependencies) { throw new MergeAbortedException( $"Unable to merge dependencies from {victim.Spec.Id} to {Spec.Id}: {victim.Spec.Id} doesn't have deps for {ourGroup.Key} or netstandard2.0"); } } else { ourGroup.Value.AddRange(netstandardDeps); } } } } foreach (var ct in victim.ContentTypes) { if (!ContentTypes.ContainsKey(ct.Key)) { ContentTypes[ct.Key] = ct.Value; } } }
public BinaryDependency(IDependency original, LoadedPackage package) { Package = package; ExcludeAssets = original.ExcludeAssets; }
public void ReplaceDeps(string from, LoadedPackage to) { Spec.Dependencies.Replace(from, to); }