Skip to content

Commit

Permalink
Merge pull request #155 from OriginalSINe/feature/dependanciesGroups
Browse files Browse the repository at this point in the history
Support nuspec dependancies with the "group" xml element
  • Loading branch information
ForrestTrepte authored Oct 25, 2018
2 parents 26e6cd5 + c5ffb93 commit d9b2f22
Showing 1 changed file with 32 additions and 5 deletions.
37 changes: 32 additions & 5 deletions Assets/NuGet/Editor/NuspecFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,28 @@ public class NuspecFile
/// </summary>
public List<NuspecContentFile> Files { get; set; }

/// <summary>
/// Add a "dependancy" node;
/// </summary>
private void addDependancy(XElement dependencyElement)
{
NugetPackageIdentifier dependency = new NugetPackageIdentifier();
dependency.Id = (string)dependencyElement.Attribute("id") ?? string.Empty;
dependency.Version = (string)dependencyElement.Attribute("version") ?? string.Empty;
Dependencies.Add(dependency);
}

/// <summary>
/// Add all the "dependancy" nodes under <paramref name="dependenciesElement"/>;
/// </summary>
private void addDependancies(XElement dependenciesElement, string nuspecNamespace)
{
foreach (var dependencyElement in dependenciesElement.Elements(XName.Get("dependency", nuspecNamespace)))
{
addDependancy(dependencyElement);
}
}

/// <summary>
/// Loads the .nuspec file inside the .nupkg file at the given filepath.
/// </summary>
Expand Down Expand Up @@ -215,12 +237,17 @@ public static NuspecFile Load(XDocument nuspecDocument)
var dependenciesElement = metadata.Element(XName.Get("dependencies", nuspecNamespace));
if (dependenciesElement != null)
{
foreach (var dependencyElement in dependenciesElement.Elements(XName.Get("dependency", nuspecNamespace)))
IEnumerable<XElement> groups = dependenciesElement.Elements(XName.Get("group", nuspecNamespace)); // get groups
if (groups.Count() > 0) // if there are groups
{
foreach (var iGroup in groups) // add dependancy in game
{
nuspec.addDependancies(iGroup, nuspecNamespace);
}
}
else // no groups; add children of "dependancies"
{
NugetPackageIdentifier dependency = new NugetPackageIdentifier();
dependency.Id = (string)dependencyElement.Attribute("id") ?? string.Empty;
dependency.Version = (string)dependencyElement.Attribute("version") ?? string.Empty;
nuspec.Dependencies.Add(dependency);
nuspec.addDependancies(dependenciesElement, nuspecNamespace);
}
}

Expand Down

0 comments on commit d9b2f22

Please sign in to comment.