Port latest features from NuGet.Core 2.11

This commit is contained in:
Eric St. John 2016-01-13 08:45:47 -08:00
parent 6e1c39d764
commit f3f6a2bf52
4 changed files with 75 additions and 3 deletions

View file

@ -0,0 +1,17 @@
using System.Xml.Serialization;
namespace NuGet
{
public class ManifestContentFiles
{
public string Include { get; set; }
public string Exclude { get; set; }
public string BuildAction { get; set; }
public string CopyToOutput { get; set; }
public string Flatten { get; set; }
}
}

View file

@ -82,5 +82,7 @@ namespace NuGet
public ICollection<PackageReferenceSet> PackageAssemblyReferences { get; set; } = new List<PackageReferenceSet>();
public IEnumerable<FrameworkAssemblyReference> FrameworkAssemblies { get; set; } = new List<FrameworkAssemblyReference>();
public ICollection<ManifestContentFiles> ContentFiles { get; set; } = new List<ManifestContentFiles>();
}
}

View file

@ -27,6 +27,7 @@ namespace NuGet
DependencySets = new List<PackageDependencySet>();
FrameworkAssemblies = new List<FrameworkAssemblyReference>();
PackageAssemblyReferences = new List<PackageReferenceSet>();
ContentFiles = new List<ManifestContentFiles>();
Authors = new List<string>();
Owners = new List<string>();
Tags = new List<string>();
@ -152,6 +153,12 @@ namespace NuGet
private set;
}
public List<ManifestContentFiles> ContentFiles
{
get;
private set;
}
public Version MinClientVersion
{
get;
@ -292,6 +299,7 @@ namespace NuGet
AppendIfNotNull(DependencySets, manifestMetadata.DependencySets);
AppendIfNotNull(FrameworkAssemblies, manifestMetadata.FrameworkAssemblies);
AppendIfNotNull(PackageAssemblyReferences, manifestMetadata.PackageAssemblyReferences);
AppendIfNotNull(ContentFiles, manifestMetadata.ContentFiles);
}
public void PopulateFiles(string basePath, IEnumerable<ManifestFile> files)

View file

@ -70,6 +70,7 @@ namespace NuGet
TargetFramework));
elem.Add(GetXElementFromFrameworkAssemblies(ns, metadata.FrameworkAssemblies));
elem.Add(GetXElementFromManifestContentFiles(ns, metadata.ContentFiles));
return elem;
}
@ -127,6 +128,8 @@ namespace NuGet
metadata.FrameworkAssemblies = GetFrameworkAssembliesFromXElement(ns, metadataElement);
metadata.ContentFiles = GetManifestContentFilesFromXElement(ns, metadataElement);
Manifest manifest = new Manifest(metadata);
var files = GetManifestFilesFromXElement(ns, element);
@ -246,13 +249,17 @@ namespace NuGet
{
return new XElement(ns + "dependency",
new XAttribute("id", dependency.Id),
dependency.VersionRange != null ? new XAttribute("version", dependency.VersionRange.ToString()) : null);
dependency.VersionRange != null ? new XAttribute("version", dependency.VersionRange.ToString()) : null,
dependency.Include != null && dependency.Include.Any() ? new XAttribute("include", string.Join(",", dependency.Include)) : null,
dependency.Exclude != null && dependency.Exclude.Any() ? new XAttribute("exclude", string.Join(",", dependency.Exclude)) : null);
}
private static PackageDependency GetPackageDependencyFromXElement(XElement element)
{
return new PackageDependency(element.Attribute("id").Value,
ConvertIfNotNull(element.Attribute("version")?.Value, s => VersionRange.Parse(s)));
ConvertIfNotNull(element.Attribute("version")?.Value, s => VersionRange.Parse(s)),
ConvertIfNotNull(element.Attribute("include")?.Value, s => s.Split(',')),
ConvertIfNotNull(element.Attribute("exclude")?.Value, s => s.Split(',')));
}
private static XElement GetXElementFromFrameworkAssemblies(XNamespace ns, IEnumerable<FrameworkAssemblyReference> references)
@ -316,7 +323,45 @@ namespace NuGet
return filesElement.Elements(ns + File).Select(f =>
new ManifestFile(f.Attribute("src").Value,
f.Attribute("target").Value,
f.Attribute("exclude").Value));
f.Attribute("exclude")?.Value));
}
private static XElement GetXElementFromManifestContentFiles(XNamespace ns, IEnumerable<ManifestContentFiles> contentFiles)
{
if (contentFiles == null || !contentFiles.Any())
{
return null;
}
return new XElement(ns + "contentFiles",
contentFiles.Select(file =>
new XElement(ns + File,
new XAttribute("include", file.Include),
new XAttribute("exclude", file.Exclude),
new XAttribute("buildAction", file.BuildAction),
new XAttribute("copyToOutput", file.CopyToOutput),
new XAttribute("flatten", file.Flatten)
)));
}
private static ICollection<ManifestContentFiles> GetManifestContentFilesFromXElement(XNamespace ns, XElement parent)
{
var contentFilesElement = parent.Element(ns + "contentFiles");
if (contentFilesElement == null)
{
return null;
}
return contentFilesElement.Elements(ns + File).Select(cf =>
new ManifestContentFiles()
{
Include = cf.Attribute("include")?.Value,
Exclude = cf.Attribute("exclude")?.Value,
BuildAction = cf.Attribute("buildAction")?.Value,
CopyToOutput = cf.Attribute("copyToOutput")?.Value,
Flatten = cf.Attribute("flatten")?.Value,
}).ToArray();
}
private static void AddElementIfNotNull<T>(XElement parent, XNamespace ns, string name, T value)