diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommandRunner.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommandRunner.cs index 2e96cd3c9c6..62eea3e3898 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommandRunner.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Commands/PackageReferenceCommands/ListPackage/ListPackageCommandRunner.cs @@ -115,7 +115,7 @@ private async Task GetProjectMetadataAsync( List<FrameworkPackages> frameworks; try { - frameworks = msBuild.GetResolvedVersions(project.FullPath, listPackageArgs.Frameworks, assetsFile, listPackageArgs.IncludeTransitive, includeProjects: listPackageArgs.ReportType == ReportType.Default); + frameworks = msBuild.GetResolvedVersions(project.FullPath, listPackageArgs.Frameworks, assetsFile, listPackageArgs.IncludeTransitive); } catch (InvalidOperationException ex) { diff --git a/src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs b/src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs index 8362b30cf95..5d1fd5bb6e4 100644 --- a/src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs +++ b/src/NuGet.Core/NuGet.CommandLine.XPlat/Utility/MSBuildAPIUtility.cs @@ -652,11 +652,10 @@ internal static bool IsPackageReferenceProject(Project project) /// <param name="userInputFrameworks">A list of frameworks</param> /// <param name="assetsFile">Assets file for all targets and libraries</param> /// <param name="transitive">Include transitive packages/projects in the result</param> - /// <param name="includeProjects">Include project references in top-level and transitive package lists</param> /// <returns>FrameworkPackages collection with top-level and transitive package/project /// references for each framework, or null on error</returns> internal List<FrameworkPackages> GetResolvedVersions( - string projectPath, IEnumerable<string> userInputFrameworks, LockFile assetsFile, bool transitive, bool includeProjects) + string projectPath, IEnumerable<string> userInputFrameworks, LockFile assetsFile, bool transitive) { if (userInputFrameworks == null) { @@ -773,7 +772,7 @@ internal List<FrameworkPackages> GetResolvedVersions( installedPackage.AutoReference = topLevelPackage.AutoReferenced; - if (library.Type != "project" || includeProjects) + if (library.Type != "project") { topLevelPackages.Add(installedPackage); } @@ -789,7 +788,7 @@ internal List<FrameworkPackages> GetResolvedVersions( .Build() }; - if (library.Type != "project" || includeProjects) + if (library.Type != "project") { transitivePackages.Add(installedPackage); } diff --git a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetListPackageTests.cs b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetListPackageTests.cs index 79a7236cbcc..301e68c35d5 100644 --- a/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetListPackageTests.cs +++ b/test/NuGet.Core.FuncTests/Dotnet.Integration.Test/DotnetListPackageTests.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.IO; using System.Linq; -using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using System.Xml.Linq; @@ -122,6 +121,70 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async( } } + [PlatformTheory(Platform.Windows)] + [InlineData("")] + [InlineData(" --outdated")] + [InlineData(" --vulnerable")] + [InlineData(" --deprecated")] + public async Task DotnetListPackage_DoesNotReturnProjects(string args) + { + using (var pathContext = _fixture.CreateSimpleTestPathContext()) + { + string directDependencyProjectName = $"{ProjectName}Dependency"; + string transitiveDependencyProjectName = $"{ProjectName}TransitiveDependency"; + var projectA = XPlatTestUtils.CreateProject(ProjectName, pathContext, "net46"); + var projectB = XPlatTestUtils.CreateProject(directDependencyProjectName, pathContext, "net46"); + var projectC = XPlatTestUtils.CreateProject(transitiveDependencyProjectName, pathContext, "net46"); + + var packageX = XPlatTestUtils.CreatePackage(packageId: "packageX"); + var packageY = XPlatTestUtils.CreatePackage(packageId: "packageY"); + var packageZ = XPlatTestUtils.CreatePackage(packageId: "packageZ"); + var packageT = XPlatTestUtils.CreatePackage(packageId: "packageT"); + packageX.Dependencies.Add(packageT); + packageY.Dependencies.Add(packageT); + packageZ.Dependencies.Add(packageT); + + // Generate Package + await SimpleTestPackageUtility.CreateFolderFeedV3Async( + pathContext.PackageSource, + PackageSaveMode.Defaultv3, + packageX, + packageY, + packageZ, + packageT); + + _fixture.RunDotnetExpectSuccess(Directory.GetParent(projectA.ProjectPath).FullName, + $"add {projectA.ProjectPath} reference {projectB.ProjectPath}"); + + _fixture.RunDotnetExpectSuccess(Directory.GetParent(projectA.ProjectPath).FullName, + $"add {projectB.ProjectPath} reference {projectC.ProjectPath}"); + + _fixture.RunDotnetExpectSuccess(Directory.GetParent(projectB.ProjectPath).FullName, + $"add {projectA.ProjectPath} package packageX --no-restore"); + + _fixture.RunDotnetExpectSuccess(Directory.GetParent(projectB.ProjectPath).FullName, + $"add {projectB.ProjectPath} package packageY --no-restore"); + + _fixture.RunDotnetExpectSuccess(Directory.GetParent(projectB.ProjectPath).FullName, + $"add {projectC.ProjectPath} package packageZ --no-restore"); + + _fixture.RunDotnetExpectSuccess(Directory.GetParent(projectA.ProjectPath).FullName, + $"restore {projectA.ProjectName}.csproj"); + + CommandRunnerResult listResult = _fixture.RunDotnetExpectSuccess(Directory.GetParent(projectA.ProjectPath).FullName, + $"list {projectA.ProjectPath} package{args}"); + + Assert.False(ContainsIgnoringSpaces(listResult.AllOutput, projectB.ProjectName)); + Assert.False(ContainsIgnoringSpaces(listResult.AllOutput, projectC.ProjectName)); + + listResult = _fixture.RunDotnetExpectSuccess(Directory.GetParent(projectA.ProjectPath).FullName, + $"list {projectA.ProjectPath} package{args} --include-transitive"); + + Assert.False(ContainsIgnoringSpaces(listResult.AllOutput, projectB.ProjectName)); + Assert.False(ContainsIgnoringSpaces(listResult.AllOutput, projectC.ProjectName)); + } + } + [PlatformTheory(Platform.Windows)] [InlineData("", "net48", null)] [InlineData("", "net46", null)] @@ -286,55 +349,6 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async( } } - [PlatformTheory(Platform.Windows)] - [InlineData(false, false)] - [InlineData(true, false)] - [InlineData(false, true)] - [InlineData(true, true)] - public void DotnetListPackage_ProjectReference_Succeeds(bool includeTransitive, bool outdated) - { - // Arrange - using (var pathContext = _fixture.CreateSimpleTestPathContext()) - { - var projectA = XPlatTestUtils.CreateProject("ProjectA", pathContext, "net46"); - var projectB = XPlatTestUtils.CreateProject("ProjectB", pathContext, "net46"); - - _fixture.RunDotnetExpectSuccess(Directory.GetParent(projectA.ProjectPath).FullName, - $"add {projectA.ProjectPath} reference {projectB.ProjectPath}"); - - _fixture.RunDotnetExpectSuccess(Directory.GetParent(projectA.ProjectPath).FullName, - $"restore {projectA.ProjectName}.csproj"); - - var argsBuilder = new StringBuilder(); - if (includeTransitive) - { - argsBuilder.Append(" --include-transitive"); - } - if (outdated) - { - argsBuilder.Append(" --outdated"); - } - - // Act - CommandRunnerResult listResult = _fixture.RunDotnetExpectSuccess(Directory.GetParent(projectA.ProjectPath).FullName, - $"list {projectA.ProjectPath} package {argsBuilder}"); - - // Assert - if (outdated) - { - Assert.Contains("The given project `ProjectA` has no updates given the current sources.", listResult.AllOutput); - } - else if (includeTransitive) - { - Assert.Contains("ProjectB", listResult.AllOutput); - } - else - { - Assert.Contains("No packages were found for this framework.", listResult.AllOutput); - } - } - } - [PlatformFact(Platform.Windows)] public async Task DotnetListPackage_OutdatedWithNoVersionsFound_Succeeds() { diff --git a/test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/XplatListPackageJsonRendererTests.cs b/test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/XplatListPackageJsonRendererTests.cs index 27d52400d60..3bcd1701f88 100644 --- a/test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/XplatListPackageJsonRendererTests.cs +++ b/test/NuGet.Core.FuncTests/NuGet.XPlat.FuncTest/XplatListPackageJsonRendererTests.cs @@ -68,7 +68,7 @@ public void JsonRenderer_ListPackage_SucceedsAsync() requestedVersion : "2.0.0", resolvedVersion : "2.0.0") }, - // Below transitive packages shouldn't be in json output because this report doesn't have --include-transive option. + // Below transitive packages shouldn't be in json output because this report doesn't have --include-transitive option. TransitivePackages = new List<ListReportPackage>() { new ListReportPackage( @@ -695,7 +695,7 @@ public void JsonRenderer_ListPackage_IncludeTransitives_SucceedsAsync() requestedVersion : "2.0.0", resolvedVersion : "2.0.0") }, - // Below transitive packages should be in json output because this report has --include-transive option. + // Below transitive packages should be in json output because this report has --include-transitive option. TransitivePackages = new List<ListReportPackage>() { new ListReportPackage(