Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Remove projects from list package output #5335

Merged
merged 5 commits into from
Aug 14, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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>
nkolev92 marked this conversation as resolved.
Show resolved Hide resolved
/// <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)
{
Expand Down Expand Up @@ -773,7 +772,7 @@ internal List<FrameworkPackages> GetResolvedVersions(

installedPackage.AutoReference = topLevelPackage.AutoReferenced;

if (library.Type != "project" || includeProjects)
if (library.Type != "project")
{
topLevelPackages.Add(installedPackage);
}
Expand All @@ -789,7 +788,7 @@ internal List<FrameworkPackages> GetResolvedVersions(
.Build()
};

if (library.Type != "project" || includeProjects)
if (library.Type != "project")
{
transitivePackages.Add(installedPackage);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down