From a389b76900e5542779b918443b56ac3f47a4ef58 Mon Sep 17 00:00:00 2001 From: v-haiboz Date: Tue, 3 Aug 2021 11:54:59 +0800 Subject: [PATCH] Bug#458021: .NET PowerShell packages Missing libraries. --- Nue/Nue.Core/PackageAtom.cs | 3 + Nue/Nue.StandardResolver/Resolver.cs | 123 +++++++++++++++++---------- Nue/Nue/Core/Extractor.cs | 9 ++ 3 files changed, 89 insertions(+), 46 deletions(-) diff --git a/Nue/Nue.Core/PackageAtom.cs b/Nue/Nue.Core/PackageAtom.cs index 0c612aa..b0fb9d5 100644 --- a/Nue/Nue.Core/PackageAtom.cs +++ b/Nue/Nue.Core/PackageAtom.cs @@ -59,6 +59,9 @@ public class PackageAdditionalProperties [JsonProperty("tfm")] public string TFM { get; set; } + [JsonProperty("includedDlls")] + public List IncludedDlls { get; set; } + [JsonProperty("excludedDlls")] public List ExcludedDlls { get; set; } } diff --git a/Nue/Nue.StandardResolver/Resolver.cs b/Nue/Nue.StandardResolver/Resolver.cs index d692ca8..ce1ad31 100644 --- a/Nue/Nue.StandardResolver/Resolver.cs +++ b/Nue/Nue.StandardResolver/Resolver.cs @@ -132,53 +132,84 @@ public bool CopyBinarySet( // differently givent that the structure is not at all reflective of what other NuGet packages encompass. if (package.IsPowerShellPackage) { - Console.WriteLine($"[info] Treating {package.Name} as a PowerShell package."); - - var helpXmlFiles = from c in Directory.GetFiles(pacManPackageLibPath) - where Path.GetFileName(c).ToLower().EndsWith("-help.xml") - select c; - - var dllFiles = new List(); - - foreach (var helpXmlFile in helpXmlFiles) - { - var workingDll = Path.GetFileName(helpXmlFile).ToLower().Replace("-help.xml", ""); - if (File.Exists(Path.Combine(pacManPackageLibPath, workingDll))) - { - dllFiles.Add(workingDll); - } + Console.WriteLine($"[info] Treating {package.Name} as a PowerShell package."); + + var dllFiles = new List(); + if (package.CustomProperties.IncludedDlls != null && package.CustomProperties.IncludedDlls.Count != 0) + { + dllFiles = Directory.GetFiles(pacManPackageLibPath, "*.*", SearchOption.AllDirectories) + .Where(s => s.EndsWith(".dll")).ToList(); + + foreach (var dll in dllFiles) + { + var test = package.CustomProperties.IncludedDlls.Any(d => d.IsMatch(Path.GetFileName(dll))); + + if (package.CustomProperties.IncludedDlls.Any(d => d.IsMatch(Path.GetFileName(dll))) && ( + package.CustomProperties.ExcludedDlls == null || + package.CustomProperties.ExcludedDlls.Count == 0 || + !package.CustomProperties.ExcludedDlls.Any(d => d.IsMatch(Path.GetFileName(dll))))) + { + File.Copy(dll, + Path.Combine(packageContainerPath, Path.GetFileName(dll)), + true); + } + else + { + if (!Directory.Exists(packageDependencyContainerPath)) + { + Directory.CreateDirectory(packageDependencyContainerPath); + } + + File.Copy(dll, Path.Combine(packageDependencyContainerPath, Path.GetFileName(dll)), true); + } + } } - - if (dllFiles.Any()) - { - foreach (var dll in dllFiles) - { - File.Copy(Path.Combine(pacManPackageLibPath, dll), Path.Combine(packageContainerPath, dll), true); - //File.Copy(Path.Combine(pacManPackageLibPath, dll + "-help.xml"), Path.Combine(packageContainerPath, Path.GetFileNameWithoutExtension(dll) + ".xml"), true); - } - - var dependencies = (from c in Directory.GetFiles(pacManPackageLibPath) - where !dllFiles.Contains(Path.GetFileName(c).ToLower()) && Path.GetFileName(c).EndsWith(".dll") - select c).ToList(); - if ((tfm.StartsWith("net46") || tfm.StartsWith("net47") || tfm.StartsWith("net48")) - && Directory.Exists(Path.Combine(pacManPackageLibPath, "PreloadAssemblies"))) - { - dependencies.AddRange(Directory.GetFiles(Path.Combine(pacManPackageLibPath, "PreloadAssemblies"))); - } - if (tfm.StartsWith("netcoreapp") - && Directory.Exists(Path.Combine(pacManPackageLibPath, "NetCoreAssemblies"))) - { - dependencies.AddRange(Directory.GetFiles(Path.Combine(pacManPackageLibPath, "NetCoreAssemblies"))); - } - if (dependencies.Count > 0) - { - Directory.CreateDirectory(packageDependencyContainerPath); - - foreach (var dependency in dependencies) - { - - File.Copy(dependency, Path.Combine(packageDependencyContainerPath, Path.GetFileName(dependency)), true); - } + else + { + var helpXmlFiles = from c in Directory.GetFiles(pacManPackageLibPath) + where Path.GetFileName(c).ToLower().EndsWith("-help.xml") + select c; + + foreach (var helpXmlFile in helpXmlFiles) + { + var workingDll = Path.GetFileName(helpXmlFile).ToLower().Replace("-help.xml", ""); + if (File.Exists(Path.Combine(pacManPackageLibPath, workingDll))) + { + dllFiles.Add(workingDll); + } + } + + if (dllFiles.Any()) + { + foreach (var dll in dllFiles) + { + File.Copy(Path.Combine(pacManPackageLibPath, dll), Path.Combine(packageContainerPath, dll), true); + //File.Copy(Path.Combine(pacManPackageLibPath, dll + "-help.xml"), Path.Combine(packageContainerPath, Path.GetFileNameWithoutExtension(dll) + ".xml"), true); + } + + var dependencies = (from c in Directory.GetFiles(pacManPackageLibPath) + where !dllFiles.Contains(Path.GetFileName(c).ToLower()) && Path.GetFileName(c).EndsWith(".dll") + select c).ToList(); + if ((tfm.StartsWith("net46") || tfm.StartsWith("net47") || tfm.StartsWith("net48")) + && Directory.Exists(Path.Combine(pacManPackageLibPath, "PreloadAssemblies"))) + { + dependencies.AddRange(Directory.GetFiles(Path.Combine(pacManPackageLibPath, "PreloadAssemblies"))); + } + if (tfm.StartsWith("netcoreapp") + && Directory.Exists(Path.Combine(pacManPackageLibPath, "NetCoreAssemblies"))) + { + dependencies.AddRange(Directory.GetFiles(Path.Combine(pacManPackageLibPath, "NetCoreAssemblies"))); + } + if (dependencies.Count > 0) + { + Directory.CreateDirectory(packageDependencyContainerPath); + + foreach (var dependency in dependencies) + { + + File.Copy(dependency, Path.Combine(packageDependencyContainerPath, Path.GetFileName(dependency)), true); + } + } } } } diff --git a/Nue/Nue/Core/Extractor.cs b/Nue/Nue/Core/Extractor.cs index a4a6fa1..af3cb16 100644 --- a/Nue/Nue/Core/Extractor.cs +++ b/Nue/Nue/Core/Extractor.cs @@ -58,6 +58,15 @@ public static void PreparePropertyBag(IEnumerable packages) package.CustomProperties.CustomFeed = feedVal; } + if (package.CustomPropertyBag.TryGetValue("includedDlls", out string includedDllVal)) + { + if (!string.IsNullOrEmpty(includedDllVal) && package.IsPowerShellPackage) + { + var includedDlls = includedDllVal.Split('|'); + package.CustomProperties.IncludedDlls = includedDlls.Select(e => Helpers.WildCardToRegex(e)).ToList(); + } + } + if (package.CustomPropertyBag.TryGetValue("excludedDlls", out string excludedDllVal)) { if (!string.IsNullOrEmpty(excludedDllVal))