From 2bfb81da2b03c05ea6d4d42f82db892e7bf517ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Bj=C3=B6rkstr=C3=B6m?= Date: Wed, 9 Aug 2017 00:17:26 +0300 Subject: [PATCH] (GH-1738) NuGetInstaller resolves correct files when package has dependencies - Fixes #1738 --- .../Unit/NuGetPackageInstallerTests.cs | 23 +++++++++++++++++++ src/Cake.NuGet/NuGetPackageInstaller.cs | 8 +++---- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/Cake.NuGet.Tests/Unit/NuGetPackageInstallerTests.cs b/src/Cake.NuGet.Tests/Unit/NuGetPackageInstallerTests.cs index d5d9f3d0dd..d3a14b69f8 100644 --- a/src/Cake.NuGet.Tests/Unit/NuGetPackageInstallerTests.cs +++ b/src/Cake.NuGet.Tests/Unit/NuGetPackageInstallerTests.cs @@ -4,6 +4,7 @@ #if !NETCORE using System.Collections.Generic; +using System.Linq; using Cake.Core.IO; using Cake.Core.Packaging; using Cake.NuGet.Tests.Fixtures; @@ -343,6 +344,28 @@ public void Should_Not_Install_If_Resource_Already_Is_Installed() "Package {0} has already been installed.", "Cake.Foo"); } + + [Fact] + public void Should_Return_Correct_Files_When_Resource_Has_Dependencies() + { + // Given + var fixture = new NuGetPackageInstallerFixture(); + fixture.FileSystem.CreateFile("/Working/nuget/cake.foo.1.2.3/Cake.Abc/Cake.Abc.dll"); + fixture.FileSystem.CreateFile("/Working/nuget/cake.foo.1.2.3/Cake.Foo/Cake.Foo.dll"); + fixture.FileSystem.CreateFile("/Working/nuget/cake.foo.1.2.3/Cake.Xyz/Cake.Xyz.dll"); + fixture.ContentResolver.GetFiles( + Arg.Any(), Arg.Any(), Arg.Any()) + .Returns(new List { Substitute.For() }); + + // When + var result = fixture.Install(); + + // Then + fixture.ContentResolver.Received(1).GetFiles( + Arg.Is(x => x.FullPath.Equals("/Working/nuget/cake.foo.1.2.3/Cake.Foo")), + fixture.Package, + PackageType.Addin); + } } } } diff --git a/src/Cake.NuGet/NuGetPackageInstaller.cs b/src/Cake.NuGet/NuGetPackageInstaller.cs index 45ef82a97d..6cec66c9c3 100644 --- a/src/Cake.NuGet/NuGetPackageInstaller.cs +++ b/src/Cake.NuGet/NuGetPackageInstaller.cs @@ -136,7 +136,7 @@ public IReadOnlyCollection Install(PackageReference package, PackageType } // Package already exist? - var packagePath = GetPackagePath(root); + var packagePath = GetPackagePath(root, package.Package); if (packagePath != null) { // Fetch available content from disc. @@ -152,7 +152,7 @@ public IReadOnlyCollection Install(PackageReference package, PackageType InstallPackage(package, path); // Try locating the install folder again. - packagePath = GetPackagePath(root); + packagePath = GetPackagePath(root, package.Package); // Get the files. var result = _contentResolver.GetFiles(packagePath, package, type); @@ -173,10 +173,10 @@ public IReadOnlyCollection Install(PackageReference package, PackageType return result; } - private static DirectoryPath GetPackagePath(IDirectory root) + private static DirectoryPath GetPackagePath(IDirectory root, string package) { var directories = root.GetDirectories("*", SearchScope.Current).ToArray(); - return directories.FirstOrDefault()?.Path; + return directories.FirstOrDefault(p => p.Path.GetDirectoryName().Equals(package, StringComparison.OrdinalIgnoreCase))?.Path; } private static DirectoryPath GetPackagePath(DirectoryPath root, PackageReference package)