ManifestDependencySet GetDependencySet(string framework) { var set = Metadata.DependencySets.Find(d => d.TargetFramework == framework); if (set == null) { set = new ManifestDependencySet() { TargetFramework = framework }; set.Dependencies = new List<ManifestDependency>(); Metadata.DependencySets.Add(set); } return set; }
private static PackageDependencySet CreatePackageDependencySet(ManifestDependencySet manifestDependencySet) { FrameworkName targetFramework = manifestDependencySet.TargetFramework == null ? null : VersionUtility.ParseFrameworkName(manifestDependencySet.TargetFramework); var dependencies = from d in manifestDependencySet.Dependencies select new PackageDependency( d.Id, String.IsNullOrEmpty(d.Version) ? null : VersionUtility.ParseVersionSpec(d.Version)); return(new PackageDependencySet(targetFramework, dependencies)); }
private static List <ManifestDependencySet> ReadDependencySets(XElement dependenciesElement) { if (!dependenciesElement.HasElements) { return(new List <ManifestDependencySet>()); } // Disallow the <dependencies> element to contain both <dependency> and // <group> child elements. Unfortunately, this cannot be enforced by XSD. if (dependenciesElement.ElementsNoNamespace("dependency").Any() && dependenciesElement.ElementsNoNamespace("group").Any()) { throw new InvalidDataException(NuGetResources.Manifest_DependenciesHasMixedElements); } var dependencies = ReadDependencies(dependenciesElement); if (dependencies.Count > 0) { // old format, <dependency> is direct child of <dependencies> var dependencySet = new ManifestDependencySet { Dependencies = dependencies }; return(new List <ManifestDependencySet> { dependencySet }); } else { var groups = dependenciesElement.ElementsNoNamespace("group"); return((from element in groups select new ManifestDependencySet { TargetFramework = element.GetOptionalAttributeValue("targetFramework").SafeTrim(), Dependencies = ReadDependencies(element) }).ToList()); } }
private static List<ManifestDependencySet> ReadDependencySet(XElement dependenciesElement) { if (!dependenciesElement.HasElements) { return new List<ManifestDependencySet>(); } // Disallow the <dependencies> element to contain both <dependency> and // <group> child elements. Unfortunately, this cannot be enforced by XSD. if (dependenciesElement.ElementsNoNamespace("dependency").Any() && dependenciesElement.ElementsNoNamespace("group").Any()) { throw new InvalidDataException(NuGetResources.Manifest_DependenciesHasMixedElements); } var dependencies = ReadDependencies(dependenciesElement); if (dependencies.Count > 0) { // old format, <dependency> is direct child of <dependencies> var dependencySet = new ManifestDependencySet { Dependencies = dependencies }; return new List<ManifestDependencySet> { dependencySet }; } else { var groups = dependenciesElement.ElementsNoNamespace("group"); return (from element in groups select new ManifestDependencySet { TargetFramework = element.GetOptionalAttributeValue("targetFramework").SafeTrim(), Dependencies = ReadDependencies(element) }).ToList(); } }
private static PackageDependencySet CreatePackageDependencySet(ManifestDependencySet manifestDependencySet) { FrameworkName targetFramework = manifestDependencySet.TargetFramework == null ? null : VersionUtility.ParseFrameworkName(manifestDependencySet.TargetFramework); var dependencies = from d in manifestDependencySet.Dependencies select new PackageDependency( d.Id, String.IsNullOrEmpty(d.Version) ? null : VersionUtility.ParseVersionSpec(d.Version)); return new PackageDependencySet(targetFramework, dependencies); }
private static PackageDependencySet CreatePackageDependencySet(ManifestDependencySet manifestDependencySet) => new PackageDependencySet((manifestDependencySet.TargetFramework == null) ? null : VersionUtility.ParseFrameworkName(manifestDependencySet.TargetFramework), from d in manifestDependencySet.Dependencies select new PackageDependency(d.Id, string.IsNullOrEmpty(d.Version) ? null : VersionUtility.ParseVersionSpec(d.Version)));
static Manifest InitiateManifestFromAssembly(Assembly assembly, IEnumerable<PackageReference> deps){ Manifest manifest = new Manifest(); AssemblyInfo ainfo = new AssemblyInfo(assembly); //Version manifest.Metadata.Version = ManifestVersionFromAssembly(ainfo); // Copyright manifest.Metadata.Copyright = ainfo.Copyright; // Authors if (ainfo.Authors != null) { manifest.Metadata.Authors = ainfo.Authors.Keys.Aggregate((key, next) => key + "," + next); manifest.Metadata.Owners = ainfo.Authors.Keys.Aggregate((key, next) => key + "," + next); } // Description manifest.Metadata.Description = ainfo.Description; // Icon Url if ( ainfo.IconUrl != null ) manifest.Metadata.IconUrl = ainfo.IconUrl.ToString(); // Id manifest.Metadata.Id = ainfo.ProductTitle; // License Url if (ainfo.LicenseUrl != null) manifest.Metadata.LicenseUrl = ainfo.LicenseUrl.ToString(); // Project Url if (ainfo.ProjectUrl != null) manifest.Metadata.ProjectUrl = ainfo.ProjectUrl.ToString(); // Tags manifest.Metadata.Tags = ainfo.Tags; // Title manifest.Metadata.Title = ainfo.ProductTitle; // Dependencies if (deps != null) { manifest.Metadata.DependencySets = new List<ManifestDependencySet>(); foreach (var frameworkVersion in deps.Select<PackageReference, FrameworkName>(pr => pr.TargetFramework).Distinct().ToArray()) { NetPortableProfile npp = new NetPortableProfile("test", new FrameworkName[1]{ frameworkVersion }); ManifestDependencySet mds = new ManifestDependencySet(); mds.Dependencies = new List<ManifestDependency>(); mds.TargetFramework = npp.CustomProfileString; manifest.Metadata.DependencySets.Add(mds); foreach (var dep in deps.Where(d => d.TargetFramework == frameworkVersion).ToArray()) { ManifestDependency md = new ManifestDependency(); md.Id = dep.Id; md.Version = dep.Version.ToNormalizedString(); mds.Dependencies.Add(md); } } } return manifest; }
private static void AddDependencySet(ManifestMetadata metadata, params IPackage[] dependsOn) { if (metadata.DependencySets == null) { metadata.DependencySets = new List<ManifestDependencySet>(); } ManifestDependencySet newDependencySet = new ManifestDependencySet(); newDependencySet.Dependencies = new List<ManifestDependency>(); foreach (IPackage dependency in dependsOn) { newDependencySet.Dependencies.Add(new ManifestDependency() { Id = dependency.Id, Version = dependency.Version.ToString(), }); } metadata.DependencySets.Add(newDependencySet); }