Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix for correctly including packages.config and internalPackages.config from Nuget-Project. #5

Open
wants to merge 4 commits into
base: feature/2.14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions NuGetPack.UnitTests/NuGetPackTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,31 @@ public void TestGetDependenciesInner()
&& ((XElement)obj).Attribute("version").Value == "1.24.0");
}

[TestMethod]
public void TestGetDependencies_InternalPackages()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test passes with and without the fix

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, of course, it was a wrong test. Correction made.

{
var nuspecFolder = Path.GetDirectoryName(nuProj2Dll);

var creator = new NuspecCreator();

XAttribute attribute;
var elements = creator.GetElements(
nuspecFolder, nuProj2Csproj, isDebugVariable, true, false, null, out attribute);

var dependencies = elements.Where(r => r.ElementType == ElementType.NuGetDependency)
.Select(r => r.Element).ToList();

LinqAssert.Count(dependencies, 2);

LinqAssert.Count(dependencies.Where(r =>
r.Attribute("id").Value == "FakeItEasy"
&& r.Attribute("version").Value == "1.24.0"), 1);

LinqAssert.Count(dependencies.Where(r =>
r.Attribute("id").Value == "PubComp.Building.Demo.Package1"
&& r.Attribute("version").Value == "1.4.1"), 1);
}

[TestMethod]
public void TestGetDependenciesViaReferenceInner1()
{
Expand Down
34 changes: 34 additions & 0 deletions NuGetPack/DependencyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,38 @@ public DependencyInfo(ElementType elementType, XElement element)
this.Element = element;
}
}

class DependencyInfoComparer : IEqualityComparer<DependencyInfo>
{
#region IEqualityComparer<XElement> Members

public bool Equals(DependencyInfo x, DependencyInfo y)
{
return (string)x.Element.FirstAttribute.Value.ToLower() == (string)y.Element.FirstAttribute.Value.ToLower();
}

public int GetHashCode(DependencyInfo obj)
{
return ((string)obj.Element.FirstAttribute.Value.ToLower()).GetHashCode();
}

#endregion
}

class XElementComparer : IEqualityComparer<XElement>
{
#region IEqualityComparer<XElement> Members

public bool Equals(XElement x, XElement y)
{
return (string)x.FirstAttribute == (string)y.FirstAttribute;
}

public int GetHashCode(XElement obj)
{
return ((string)obj.FirstAttribute).GetHashCode();
}

#endregion
}
}
24 changes: 20 additions & 4 deletions NuGetPack/NuspecCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace PubComp.Building.NuGetPack
// ReSharper disable once PartialTypeWithSinglePart
public partial class NuspecCreator
{
private string PackageVersion {get; set;}
public void CreatePackages(
string binFolder, string solutionFolder, bool isDebug,
bool doCreatePkg = true, bool doIncludeCurrentProj = false,
Expand Down Expand Up @@ -211,6 +212,7 @@ public XDocument CreateNuspec(

var fileVersion = FileVersionInfo.GetVersionInfo(assemblyPath);
var version = GetVersion(fileVersion, preReleaseSuffixOverride);
PackageVersion = version;

var owners = fileVersion.CompanyName;

Expand Down Expand Up @@ -397,8 +399,13 @@ public XDocument CreateNuspec(
.Select(el => el.Element)
.ToList();

frameworkReferences.AddRange(
elements.Where(el => el.ElementType == ElementType.FrameworkReference)
.Distinct(new DependencyInfoComparer())
.Select(el => el.Element).ToList());

metadataElement.Add(new XElement("frameworkAssemblies",
frameworkReferences));
frameworkReferences.Distinct(new XElementComparer())));
}

var doc = new XDocument(
Expand Down Expand Up @@ -440,12 +447,19 @@ public List<DependencyInfo> GetDependencies(string packagesFile)
foreach (var package in packages)
{
// ReSharper disable PossibleNullReferenceException
string version = PackageVersion;
if (package.Attribute("version") != null )
{
version = package.Attribute("version").Value;
}

result.Add(
new DependencyInfo(
ElementType.NuGetDependency,
new XElement("dependency",
new XAttribute("id", package.Attribute("id").Value),
new XAttribute("version", package.Attribute("version").Value))));
new XAttribute("version", version)))
);
// ReSharper enable PossibleNullReferenceException
}

Expand Down Expand Up @@ -554,8 +568,8 @@ public List<DependencyInfo> GetElements(

DebugOut(() => "ProjectFolder = " + projectFolder);

var packagesFile = Path.Combine(projectPath, "packages.config");
var internalPackagesFile = Path.Combine(projectPath, "internalPackages.config");
var packagesFile = Path.Combine(projectFolder, "packages.config");
var internalPackagesFile = Path.Combine(projectFolder, "internalPackages.config");

var result = new List<DependencyInfo>();

Expand Down Expand Up @@ -607,6 +621,8 @@ public List<DependencyInfo> GetElements(
DebugOut(() => "projPath = " + refProjPath);

result.AddRange(GetBinaryReferences(nuspecFolder, refProjFolder, refProjPath, isDebug, nuspecFolder));

result.AddRange(GetFrameworkReferences(refProjFolder, refProjPath));

if (doIncludeSources)
result.AddRange(GetSourceFiles(nuspecFolder, refProjFolder, refProjPath));
Expand Down