/// <summary> /// Installs the (unzipped) nuget package into <see cref="PackagesPath"/> directory. /// </summary> /// <param name="nugetContentPath">Content of the unzipped nuget.</param> /// <param name="nuspecreader">Outputs nuspec file.</param> /// <returns>Whether the installation was successful.</returns> public Scheme.InstalledPackage InstallPackage(string nugetContentPath, out INuspecCoreReader nuspecreader) { var nuspecs = Directory.GetFiles(nugetContentPath, "*.nuspec"); if (nuspecs.Length == 1) { var nuspec = new NuspecCoreReader(XDocument.Load(nuspecs[0])); // TODO: restore dependencies // copy lib to packages var dllsource = Path.Combine(nugetContentPath, "lib/netstandard2.0"); var dlltarget = Path.GetFullPath(Path.Combine(PackagesPath, nuspec.GetId(), nuspec.GetVersion().ToNormalizedString())); Directory.CreateDirectory(dlltarget); foreach (var fpath in Directory.GetFiles(dllsource)) { var filetarget = Path.Combine(dlltarget, Path.GetFileName(fpath)); if (!File.Exists(filetarget)) { File.Move(fpath, filetarget); } } // TODO: try to delete old versions of the package // var package = new Scheme.InstalledPackage { pluginId = nuspec.GetId(), version = nuspec.GetVersion().ToNormalizedString(), active = false }; // add packageId to packages.json UpdatePackagesJson(json => { json.Add(package); }); // nuspecreader = nuspec; return(package); } else { nuspecreader = null; return(null); } }
private static void CopyNupkgToOutput(DirectoryInfo directory, string moduleName, string packagePath, PseudoNuspecBuilder builder) { using (var sourceFile = ZipFile.OpenRead(packagePath)) { var nuspecFile = sourceFile.Entries.Single(x => x.Name.EndsWith(".nuspec")); TryParseFrameworkFromName(nuspecFile.Name, moduleName, out var framework); using (var stream = nuspecFile.Open()) { var reader = new NuspecCoreReader(stream); var id = reader.GetId(); if (framework == null) { if (Enum.TryParse <MazeFramework>(id.Split('.').Last(), out var fw)) { framework = fw; } else { Console.WriteLine($"Package {id} could not be associated to an Maze framework. It will be included as a reference."); var tempFolder = Path.Combine(directory.FullName, reader.GetId()); ExtractPackage(tempFolder, sourceFile); builder.IncludedReferences.Add(new IncludedReference { Dependencies = reader.GetDependencies().ToList(), ContentPath = tempFolder, Id = reader.GetId() }); return; } } builder.Import(reader, framework.Value); } var nuGetFramework = framework.Value.ToNuGetFramework(); ExtractPackage(Path.Combine(directory.FullName, "lib", nuGetFramework.GetShortFolderName()), sourceFile); } }