diff --git a/src/Cake.Common.Tests/Fixtures/Tools/DotNet/Package/List/DotNetPackageListerFixture.cs b/src/Cake.Common.Tests/Fixtures/Tools/DotNet/Package/List/DotNetPackageListerFixture.cs new file mode 100644 index 0000000000..6f0cd378a4 --- /dev/null +++ b/src/Cake.Common.Tests/Fixtures/Tools/DotNet/Package/List/DotNetPackageListerFixture.cs @@ -0,0 +1,49 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Cake.Common.Tools.DotNet.Package.List; + +namespace Cake.Common.Tests.Fixtures.Tools.DotNet.Package.List +{ + internal sealed class DotNetPackageListerFixture : DotNetFixture + { + public string Project { get; set; } + public DotNetPackageList Result { get; set; } + + public void GivenPackgeListResult() + { + ProcessRunner.Process.SetStandardOutput(new string[] + { + "{", + " \"version\": 1,", + " \"parameters\": \"\",", + " \"projects\": [", + " {", + " \"path\": \"src/lib/MyProject.csproj\",", + " \"frameworks\": [", + " {", + " \"framework\": \"netstandard2.0\",", + " \"topLevelPackages\": [", + " {", + " \"id\": \"NETStandard.Library\",", + " \"requestedVersion\": \"[2.0.3, )\",", + " \"resolvedVersion\": \"2.0.3\",", + " \"autoReferenced\": \"true\"", + " }", + " ]", + " }", + " ]", + " }", + " ]", + "}" + }); + } + + protected override void RunTool() + { + var tool = new DotNetPackageLister(FileSystem, Environment, ProcessRunner, Tools); + Result = tool.List(Project, Settings); + } + } +} diff --git a/src/Cake.Common.Tests/Unit/Tools/DotNet/Package/List/DotNetPackageListerTests.cs b/src/Cake.Common.Tests/Unit/Tools/DotNet/Package/List/DotNetPackageListerTests.cs new file mode 100644 index 0000000000..55e2c03fa6 --- /dev/null +++ b/src/Cake.Common.Tests/Unit/Tools/DotNet/Package/List/DotNetPackageListerTests.cs @@ -0,0 +1,118 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Cake.Common.Tests.Fixtures.Tools.DotNet.Package.List; +using Cake.Common.Tools.DotNet; +using Cake.Testing; +using Xunit; + +namespace Cake.Common.Tests.Unit.Tools.DotNet.Package.List +{ + public sealed class DotNetPackageListerTests + { + public sealed class TheListMethod + { + [Fact] + public void Should_Throw_If_Process_Was_Not_Started() + { + // Given + var fixture = new DotNetPackageListerFixture(); + fixture.GivenProcessCannotStart(); + + // When + var result = Record.Exception(() => fixture.Run()); + + // Then + AssertEx.IsCakeException(result, ".NET CLI: Process was not started."); + } + + [Fact] + public void Should_Throw_If_Process_Has_A_Non_Zero_Exit_Code() + { + // Given + var fixture = new DotNetPackageListerFixture(); + fixture.GivenProcessExitsWithCode(1); + + // When + var result = Record.Exception(() => fixture.Run()); + + // Then + AssertEx.IsCakeException(result, ".NET CLI: Process returned an error (exit code 1)."); + } + + [Fact] + public void Should_Throw_If_Settings_Are_Null() + { + // Given + var fixture = new DotNetPackageListerFixture(); + fixture.Settings = null; + fixture.GivenDefaultToolDoNotExist(); + + // When + var result = Record.Exception(() => fixture.Run()); + + // Then + AssertEx.IsArgumentNullException(result, "settings"); + } + + [Fact] + public void Should_Add_Project_Argument() + { + // Given + var fixture = new DotNetPackageListerFixture(); + fixture.Project = "ToDo.csproj"; + fixture.GivenPackgeListResult(); + + // When + var result = fixture.Run(); + + // Then + Assert.Equal("list \"ToDo.csproj\" package --format json --output-version 1", result.Args); + } + + [Fact] + public void Should_Add_Additional_Arguments() + { + // Given + var fixture = new DotNetPackageListerFixture(); + fixture.Settings.ConfigFile = "./nuget.config"; + fixture.Settings.Deprecated = true; + fixture.Settings.Framework = "net7.0"; + fixture.Settings.HighestMinor = true; + fixture.Settings.HighestPatch = true; + fixture.Settings.Prerelease = true; + fixture.Settings.Transitive = true; + fixture.Settings.Interactive = true; + fixture.Settings.Outdated = true; + fixture.Settings.Source.Add("http://www.nuget.org/api/v2/package"); + fixture.Settings.Source.Add("http://www.symbolserver.org/"); + fixture.Settings.Vulnerable = true; + fixture.GivenPackgeListResult(); + + // When + var result = fixture.Run(); + + // Then + var expected = "list package --config \"/Working/nuget.config\" --deprecated --framework net7.0 --highest-minor --highest-patch --include-prerelease --include-transitive --interactive --outdated "; + expected += "--source \"http://www.nuget.org/api/v2/package\" --source \"http://www.symbolserver.org/\" --vulnerable --format json --output-version 1"; + Assert.Equal(expected, result.Args); + } + + [Fact] + public void Should_Return_Correct_Result() + { + // Given + var fixture = new DotNetPackageListerFixture(); + fixture.GivenPackgeListResult(); + + // When + var result = fixture.Run(); + + // Then + Assert.Equal(1, fixture.Result.Version); + Assert.Contains(fixture.Result.Projects, item => item.Path == "src/lib/MyProject.csproj"); + } + } + } +} diff --git a/src/Cake.Common/Tools/DotNet/DotNetAliases.cs b/src/Cake.Common/Tools/DotNet/DotNetAliases.cs index c84101cd00..32f2ee2c8a 100644 --- a/src/Cake.Common/Tools/DotNet/DotNetAliases.cs +++ b/src/Cake.Common/Tools/DotNet/DotNetAliases.cs @@ -16,6 +16,7 @@ using Cake.Common.Tools.DotNet.NuGet.Source; using Cake.Common.Tools.DotNet.Pack; using Cake.Common.Tools.DotNet.Package.Add; +using Cake.Common.Tools.DotNet.Package.List; using Cake.Common.Tools.DotNet.Package.Remove; using Cake.Common.Tools.DotNet.Package.Search; using Cake.Common.Tools.DotNet.Publish; @@ -2622,5 +2623,78 @@ public static IEnumerable DotNetSearchPackage(this ICak var runner = new DotNetPackageSearcher(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); return runner.Search(null, settings); } + + /// + /// Lists the package references for a project or solution. + /// + /// The context. + /// The the package references. + /// + /// + /// DotNetPackageList output = DotNetListPackage(); + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("Package")] + [CakeNamespaceImport("Cake.Common.Tools.DotNet.Package.List")] + public static DotNetPackageList DotNetListPackage(this ICakeContext context) + { + return context.DotNetListPackage(null); + } + + /// + /// Lists the package references for a project or solution. + /// + /// The context. + /// The project or solution file to operate on. If not specified, the command searches the current directory for one. If more than one solution or project is found, an error is thrown. + /// The the package references. + /// + /// + /// DotNetPackageList output = DotNetListPackage("./src/MyProject/MyProject.csproj"); + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("Package")] + [CakeNamespaceImport("Cake.Common.Tools.DotNet.Package.List")] + public static DotNetPackageList DotNetListPackage(this ICakeContext context, string project) + { + return context.DotNetListPackage(project, null); + } + + /// + /// Lists the package references for a project or solution. + /// + /// The context. + /// The project or solution file to operate on. If not specified, the command searches the current directory for one. If more than one solution or project is found, an error is thrown. + /// The settings. + /// The the package references. + /// + /// + /// var settings = new DotNetPackageListSettings + /// { + /// Outdated = true + /// }; + /// + /// DotNetPackageList output = DotNetListPackage("./src/MyProject/MyProject.csproj", settings); + /// + /// + [CakeMethodAlias] + [CakeAliasCategory("Package")] + [CakeNamespaceImport("Cake.Common.Tools.DotNet.Package.List")] + public static DotNetPackageList DotNetListPackage(this ICakeContext context, string project, DotNetPackageListSettings settings) + { + if (context is null) + { + throw new ArgumentNullException(nameof(context)); + } + + if (settings is null) + { + settings = new DotNetPackageListSettings(); + } + + var lister = new DotNetPackageLister(context.FileSystem, context.Environment, context.ProcessRunner, context.Tools); + return lister.List(project, settings); + } } } diff --git a/src/Cake.Common/Tools/DotNet/Format/DotNetFormatSeverity.cs b/src/Cake.Common/Tools/DotNet/Format/DotNetFormatSeverity.cs index b501c8ef71..ceb0a48f06 100644 --- a/src/Cake.Common/Tools/DotNet/Format/DotNetFormatSeverity.cs +++ b/src/Cake.Common/Tools/DotNet/Format/DotNetFormatSeverity.cs @@ -1,4 +1,8 @@ -namespace Cake.Common.Tools.DotNet.Format +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Cake.Common.Tools.DotNet.Format { /// /// Severity of dotnet format. diff --git a/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageList.cs b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageList.cs new file mode 100644 index 0000000000..64395c5844 --- /dev/null +++ b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageList.cs @@ -0,0 +1,45 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Cake.Common.Tools.DotNet.Package.List +{ + /// + /// An result as returned by . + /// + public sealed class DotNetPackageList + { + /// + /// Gets the output version. + /// + [JsonInclude] + public int Version { get; private set; } + + /// + /// Gets the specified parameters. + /// + [JsonInclude] + public string Parameters { get; private set; } + + /// + /// Gets the problems. + /// + [JsonInclude] + public IEnumerable Problems { get; private set; } + + /// + /// Gets the used sources. + /// + [JsonInclude] + public IEnumerable Sources { get; private set; } + + /// + /// Gets the projects. + /// + [JsonInclude] + public IEnumerable Projects { get; private set; } + } +} diff --git a/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListAlternativePackageItem.cs b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListAlternativePackageItem.cs new file mode 100644 index 0000000000..ed1d291a94 --- /dev/null +++ b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListAlternativePackageItem.cs @@ -0,0 +1,26 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Cake.Common.Tools.DotNet.Package.List +{ + /// + /// The alternative package information. + /// + public sealed class DotNetPackageListAlternativePackageItem + { + /// + /// Gets the alternative package id. + /// + [JsonInclude] + public string Id { get; private set; } + + /// + /// Gets the alternative package versions. + /// + [JsonInclude] + public string VersionRange { get; private set; } + } +} diff --git a/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListFrameworkItem.cs b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListFrameworkItem.cs new file mode 100644 index 0000000000..90dc1babe2 --- /dev/null +++ b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListFrameworkItem.cs @@ -0,0 +1,33 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Cake.Common.Tools.DotNet.Package.List +{ + /// + /// The framework information. + /// + public sealed class DotNetPackageListFrameworkItem + { + /// + /// Gets the framework name. + /// + [JsonInclude] + public string Framework { get; private set; } + + /// + /// Gets the top-level packages. + /// + [JsonInclude] + public IEnumerable TopLevelPackages { get; private set; } + + /// + /// Gets transitive packages. + /// + [JsonInclude] + public IEnumerable TransitivePackages { get; private set; } + } +} diff --git a/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListPackageItem.cs b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListPackageItem.cs new file mode 100644 index 0000000000..f1c482c0e1 --- /dev/null +++ b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListPackageItem.cs @@ -0,0 +1,63 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Cake.Common.Tools.DotNet.Package.List +{ + /// + /// The package information. + /// + public sealed class DotNetPackageListPackageItem + { + /// + /// Gets the package id. + /// + [JsonInclude] + public string Id { get; private set; } + + /// + /// Gets the requested version. + /// + [JsonInclude] + public string RequestedVersion { get; private set; } + + /// + /// Gets the resolved version. + /// + [JsonInclude] + public string ResolvedVersion { get; private set; } + + /// + /// Gets a value indicating whether the package is auto-referenced. + /// + [JsonInclude] + public string AutoReferenced { get; private set; } + + /// + /// Gets the latest version. + /// + [JsonInclude] + public string LatestVersion { get; private set; } + + /// + /// Gets the deprecation reasons. + /// + [JsonInclude] + public IEnumerable DeprecationReasons { get; private set; } + + /// + /// Gets the alternative package. + /// + [JsonInclude] + public DotNetPackageListAlternativePackageItem AlternativePackage { get; private set; } + + /// + /// Gets the vulnerabilities list. + /// + [JsonInclude] + public IEnumerable Vulnerabilities { get; private set; } + } +} diff --git a/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListProblemItem.cs b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListProblemItem.cs new file mode 100644 index 0000000000..38b30abc4c --- /dev/null +++ b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListProblemItem.cs @@ -0,0 +1,32 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Text.Json.Serialization; + +namespace Cake.Common.Tools.DotNet.Package.List +{ + /// + /// The problem information. + /// + public sealed class DotNetPackageListProblemItem + { + /// + /// Gets the problem level. + /// + [JsonInclude] + public DotNetPackageListProblemType? Level { get; private set; } + + /// + /// Gets the problem text. + /// + [JsonInclude] + public string Text { get; private set; } + + /// + /// Gets the project path. + /// + [JsonInclude] + public string Project { get; private set; } + } +} diff --git a/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListProblemType.cs b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListProblemType.cs new file mode 100644 index 0000000000..1aebd7814c --- /dev/null +++ b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListProblemType.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace Cake.Common.Tools.DotNet.Package.List +{ + /// + /// The problem types. + /// + public enum DotNetPackageListProblemType + { + /// + /// Warning. + /// + Warning, + + /// + /// Error. + /// + Error + } +} diff --git a/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListProjectItem.cs b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListProjectItem.cs new file mode 100644 index 0000000000..a3a30ef713 --- /dev/null +++ b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListProjectItem.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Cake.Common.Tools.DotNet.Package.List +{ + /// + /// The project information. + /// + public sealed class DotNetPackageListProjectItem + { + /// + /// Gets the project path. + /// + [JsonInclude] + public string Path { get; private set; } + + /// + /// Gets the list of frameworks. + /// + [JsonInclude] + public IEnumerable Frameworks { get; private set; } + } +} diff --git a/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListSettings.cs b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListSettings.cs new file mode 100644 index 0000000000..d73ad10dc8 --- /dev/null +++ b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListSettings.cs @@ -0,0 +1,79 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System.Collections.Generic; +using Cake.Core.IO; + +namespace Cake.Common.Tools.DotNet.Package.List +{ + /// + /// Contains settings used by . + /// + public sealed class DotNetPackageListSettings : DotNetSettings + { + /// + /// Gets or sets the NuGet configuration file (nuget.config) to use. + /// Requires the option. + /// + public FilePath ConfigFile { get; set; } + + /// + /// Gets or sets a value indicating whether to display packages that have been deprecated. + /// + public bool Deprecated { get; set; } + + /// + /// Gets or sets a value indicating whether to list packages that have newer versions available. + /// + public bool Outdated { get; set; } + + /// + /// Gets or sets a specific framework to compile. + /// + public string Framework { get; set; } + + /// + /// Gets or sets a value indicating whether to display only the packages with a matching major version number when searching for newer packages. + /// Requires the or option. + /// + public bool HighestMinor { get; set; } + + /// + /// Gets or sets a value indicating whether to display only the packages with a matching major and minor version numbers when searching for newer packages. + /// Requires the or option. + /// + public bool HighestPatch { get; set; } + + /// + /// Gets or sets a value indicating whether to list packages with prerelease versions when searching for newer packages. + /// Requires the or option. + /// + public bool Prerelease { get; set; } + + /// + /// Gets or sets a value indicating whether to list transitive packages, in addition to the top-level packages. + /// When specifying this option, you get a list of packages that the top-level packages depend on. + /// + public bool Transitive { get; set; } + + /// + /// Gets or sets a value indicating whether to allow the command to stop and wait for user input or action. + /// For example, to complete authentication. Available since .NET Core 3.0 SDK. + /// + public bool Interactive { get; set; } + + /// + /// Gets or sets the URI of the NuGet package source to use. + /// Requires the or option. + /// + public ICollection Source { get; set; } = new List(); + + /// + /// Gets or sets a value indicating whether to list packages that have known vulnerabilities. + /// Cannot be combined with or options. + /// Nuget.org is the source of information about vulnerabilities. + /// + public bool Vulnerable { get; set; } + } +} diff --git a/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListVulnerabilityItem.cs b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListVulnerabilityItem.cs new file mode 100644 index 0000000000..b5109cc817 --- /dev/null +++ b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageListVulnerabilityItem.cs @@ -0,0 +1,27 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Text.Json.Serialization; + +namespace Cake.Common.Tools.DotNet.Package.List +{ + /// + /// The vulnerability information. + /// + public sealed class DotNetPackageListVulnerabilityItem + { + /// + /// Gets the severity level: Low, Moderate, High, Critical. + /// + [JsonInclude] + public string Severity { get; private set; } + + /// + /// Gets the URL of advisory. + /// + [JsonInclude] + public Uri AdvisoryUrl { get; private set; } + } +} diff --git a/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageLister.cs b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageLister.cs new file mode 100644 index 0000000000..0ef6db7ce5 --- /dev/null +++ b/src/Cake.Common/Tools/DotNet/Package/List/DotNetPackageLister.cs @@ -0,0 +1,154 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using System; +using System.Linq; +using System.Text.Json; +using Cake.Core; +using Cake.Core.IO; +using Cake.Core.Tooling; + +namespace Cake.Common.Tools.DotNet.Package.List +{ + /// + /// .NET package lister. + /// + public sealed class DotNetPackageLister : DotNetTool + { + private readonly ICakeEnvironment _environment; + + /// + /// Initializes a new instance of the class. + /// + /// The file system. + /// The environment. + /// The process runner. + /// The tool locator. + public DotNetPackageLister( + IFileSystem fileSystem, + ICakeEnvironment environment, + IProcessRunner processRunner, + IToolLocator tools) : base(fileSystem, environment, processRunner, tools) + { + _environment = environment; + } + + /// + /// Lists the package references for a project or solution. + /// + /// The project or solution file to operate on. If not specified, the command searches the current directory for one. If more than one solution or project is found, an error is thrown. + /// The settings. + /// A task with the GitVersion results. + public DotNetPackageList List(string project, DotNetPackageListSettings settings) + { + if (settings == null) + { + throw new ArgumentNullException(nameof(settings)); + } + + var output = string.Empty; + Run(settings, GetArguments(project, settings), new ProcessSettings { RedirectStandardOutput = true }, process => + { + output = string.Join("\n", process.GetStandardOutput()); + }); + + return JsonSerializer.Deserialize(output, new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true + }); + } + + private ProcessArgumentBuilder GetArguments(string project, DotNetPackageListSettings settings) + { + var builder = CreateArgumentBuilder(settings); + + builder.Append("list"); + + // Project path + if (project != null) + { + builder.AppendQuoted(project); + } + + builder.Append("package"); + + // Config File + if (settings.ConfigFile != null) + { + builder.AppendSwitchQuoted("--config", settings.ConfigFile.MakeAbsolute(_environment).FullPath); + } + + // Deprecated + if (settings.Deprecated) + { + builder.Append("--deprecated"); + } + + // Framework + if (!string.IsNullOrEmpty(settings.Framework)) + { + builder.AppendSwitch("--framework", settings.Framework); + } + + // Highest Minor + if (settings.HighestMinor) + { + builder.Append("--highest-minor"); + } + + // Highest Patch + if (settings.HighestPatch) + { + builder.Append("--highest-patch"); + } + + // Prerelease + if (settings.Prerelease) + { + builder.Append("--include-prerelease"); + } + + // Transitive + if (settings.Transitive) + { + builder.Append("--include-transitive"); + } + + // Interactive + if (settings.Interactive) + { + builder.Append("--interactive"); + } + + // Outdated + if (settings.Outdated) + { + builder.Append("--outdated"); + } + + // Source + if (settings.Source != null && settings.Source.Any()) + { + foreach (var source in settings.Source) + { + builder.AppendSwitchQuoted("--source", source); + } + } + + // Vulnerable + if (settings.Vulnerable) + { + builder.Append("--vulnerable"); + } + + // Format + builder.Append("--format json"); + + // Version + builder.Append("--output-version 1"); + + return builder; + } + } +} diff --git a/tests/integration/Cake.Common/Tools/DotNet/DotNetAliases.cake b/tests/integration/Cake.Common/Tools/DotNet/DotNetAliases.cake index c998c6da28..0b0f28b3b6 100644 --- a/tests/integration/Cake.Common/Tools/DotNet/DotNetAliases.cake +++ b/tests/integration/Cake.Common/Tools/DotNet/DotNetAliases.cake @@ -389,6 +389,21 @@ Task("Cake.Common.Tools.DotNet.DotNetAliases.DotNetSearchPackage") Assert.Contains(package, result.Select(x => x.Name)); }); +Task("Cake.Common.Tools.DotNet.DotNetAliases.DotNetListPackage") + .IsDependentOn("Cake.Common.Tools.DotNet.DotNetAliases.DotNetRestore") + .Does(() => +{ + // Given + var path = Paths.Temp.Combine("./Cake.Common/Tools/DotNet"); + var project = path.CombineWithFilePath("hwapp/hwapp.csproj"); + // When + DotNetRestore(project.FullPath); + var result = DotNetListPackage(project.FullPath); + // Then + Assert.Equal(1, result.Version); + Assert.Contains(result.Projects, item => item.Path == project); +}); + Task("Cake.Common.Tools.DotNet.DotNetAliases.DotNetBuildServerShutdown") .IsDependentOn("Cake.Common.Tools.DotNet.DotNetAliases.DotNetRestore") .IsDependentOn("Cake.Common.Tools.DotNet.DotNetAliases.DotNetBuild") @@ -414,6 +429,7 @@ Task("Cake.Common.Tools.DotNet.DotNetAliases.DotNetBuildServerShutdown") .IsDependentOn("Cake.Common.Tools.DotNet.DotNetAliases.DotNetRemovePackage") .IsDependentOn("Cake.Common.Tools.DotNet.DotNetAliases.DotNetAddReference") .IsDependentOn("Cake.Common.Tools.DotNet.DotNetAliases.DotNetSearchPackage") + .IsDependentOn("Cake.Common.Tools.DotNet.DotNetAliases.DotNetListPackage") .Does(() => { // When