From 2587f81bab6dd68a530c74c4117cba80942495f1 Mon Sep 17 00:00:00 2001 From: Nigusu Yenework Date: Tue, 25 Mar 2025 09:46:41 -0700 Subject: [PATCH 01/13] dotnet list package restores --- .../List/Package/ListPackageCommandParser.cs | 1 + .../Package/List/PackageListCommand.cs | 65 ++- .../Package/List/PackageListCommandParser.cs | 6 + src/Cli/dotnet/Properties/launchSettings.json | 6 +- .../Commands/PackageListCommand.cs | 35 ++ ...napshotTests.VerifyCompletions.verified.sh | 4 +- ...apshotTests.VerifyCompletions.verified.ps1 | 1 + ...apshotTests.VerifyCompletions.verified.zsh | 1 + .../GivenDotnetListPackage.cs | 20 +- .../GivenDotnetPackageList.cs | 460 ++++++++++++++++++ test/dotnet.Tests/dotnet.Tests.csproj | 1 + 11 files changed, 593 insertions(+), 7 deletions(-) create mode 100644 test/Microsoft.NET.TestFramework/Commands/PackageListCommand.cs create mode 100644 test/dotnet.Tests/dotnet-pacakge-list/GivenDotnetPackageList.cs diff --git a/src/Cli/dotnet/Commands/Hidden/List/Package/ListPackageCommandParser.cs b/src/Cli/dotnet/Commands/Hidden/List/Package/ListPackageCommandParser.cs index faa7cc354274..c491827a12cd 100644 --- a/src/Cli/dotnet/Commands/Hidden/List/Package/ListPackageCommandParser.cs +++ b/src/Cli/dotnet/Commands/Hidden/List/Package/ListPackageCommandParser.cs @@ -33,6 +33,7 @@ private static CliCommand ConstructCommand() command.Options.Add(PackageListCommandParser.InteractiveOption); command.Options.Add(PackageListCommandParser.FormatOption); command.Options.Add(PackageListCommandParser.OutputVersionOption); + command.Options.Add(PackageListCommandParser.NoRestore); command.SetAction((parseResult) => new PackageListCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs index 3f8dae9aee19..5d6371ab800e 100644 --- a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs +++ b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs @@ -6,6 +6,12 @@ using Microsoft.DotNet.Cli.Commands.NuGet; using Microsoft.DotNet.Cli.Extensions; using Microsoft.DotNet.Cli.Utils; +<<<<<<< HEAD:src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs +======= +using Microsoft.DotNet.Tools.NuGet; +using System.Globalization; +using Microsoft.DotNet.Tools.MSBuild; +>>>>>>> 27439c5902 (dotnet list package restores):src/Cli/dotnet/Commands/Package/List/ListPackageReferencesCommand.cs namespace Microsoft.DotNet.Cli.Commands.Package.List; @@ -25,7 +31,57 @@ private static string GetAbsolutePath(string currentDirectory, string relativePa public override int Execute() { - return NuGetCommand.Run(TransformArgs()); + string projectFile = GetProjectOrSolution(); + bool noRestore = _parseResult.HasOption(PackageListCommandParser.NoRestore); + int restoreExitCode = 0; + + if (!noRestore) + { + ReportOutputFormat formatOption = _parseResult.GetValue((CliOption)PackageListCommandParser.FormatOption); + restoreExitCode = RunRestore(projectFile, formatOption); + } + + return restoreExitCode == 0 + ? NuGetCommand.Run(TransformArgs(projectFile)) + : restoreExitCode; + } + + private int RunRestore(string projectOrSolution, ReportOutputFormat formatOption) + { + MSBuildForwardingApp restoringCommand = new MSBuildForwardingApp(argsToForward: ["-target:restore", projectOrSolution, "-noConsoleLogger"]); + + int exitCode = 0; + + try + { + exitCode = restoringCommand.Execute(); + } + catch (Exception) + { + exitCode = 1; + } + + if (exitCode != 0) + { + if (formatOption == ReportOutputFormat.json) + { + string jsonError = + "{\r\n" + + " \"version\": 1,\r\n" + + " \"problems\": [\r\n" + + " {\r\n" + + $" \"text\": \"{String.Format(CultureInfo.CurrentCulture, LocalizableStrings.Error_restore)}\",\r\n" + + " \"level\": \"error\"\r\n" + + " }\r\n" + + " ]\r\n" + + "}"; + Console.WriteLine(jsonError); + } + + Console.WriteLine(String.Format(CultureInfo.CurrentCulture, LocalizableStrings.Error_restore)); + } + + return exitCode; } internal static void EnforceOptionRules(ParseResult parseResult) @@ -40,7 +96,7 @@ internal static void EnforceOptionRules(ParseResult parseResult) } } - private string[] TransformArgs() + private string[] TransformArgs(string projectOrSolution) { var args = new List { @@ -49,6 +105,11 @@ private string[] TransformArgs() GetProjectOrSolution() }; +<<<<<<< HEAD:src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs +======= + args.Add(projectOrSolution); + +>>>>>>> 27439c5902 (dotnet list package restores):src/Cli/dotnet/Commands/Package/List/ListPackageReferencesCommand.cs args.AddRange(_parseResult.OptionValuesToBeForwarded(PackageListCommandParser.GetCommand())); EnforceOptionRules(_parseResult); diff --git a/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs b/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs index 6aaa53d79641..c5f4437e86d9 100644 --- a/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs +++ b/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs @@ -72,6 +72,12 @@ internal static class PackageListCommandParser public static readonly CliOption InteractiveOption = CommonOptions.InteractiveOption().ForwardIfEnabled("--interactive"); + public static readonly CliOption NoRestore = new CliOption("--no-restore") + { + Description = LocalizableStrings.CmdNoRestoreDescription, + Arity = ArgumentArity.Zero + }; + public static readonly CliOption VerbosityOption = new ForwardedOption("--verbosity", "-v") { Description = CliStrings.VerbosityOptionDescription, diff --git a/src/Cli/dotnet/Properties/launchSettings.json b/src/Cli/dotnet/Properties/launchSettings.json index facffd64a35f..dc5cb018fd9c 100644 --- a/src/Cli/dotnet/Properties/launchSettings.json +++ b/src/Cli/dotnet/Properties/launchSettings.json @@ -1,7 +1,9 @@ { "profiles": { "dotnet": { - "commandName": "Project" + "commandName": "Project", + "commandLineArgs": "package list --format json", + "workingDirectory": "N:\\trash\\p7\\p7" } } -} +} \ No newline at end of file diff --git a/test/Microsoft.NET.TestFramework/Commands/PackageListCommand.cs b/test/Microsoft.NET.TestFramework/Commands/PackageListCommand.cs new file mode 100644 index 000000000000..b99407ed4072 --- /dev/null +++ b/test/Microsoft.NET.TestFramework/Commands/PackageListCommand.cs @@ -0,0 +1,35 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Microsoft.DotNet.Cli.Utils; + +namespace Microsoft.NET.TestFramework.Commands +{ + public class PackageListCommand : DotnetCommand + { + private string? _projectName = null; + + public PackageListCommand(ITestOutputHelper log, params string[] args) : base(log, args) + { + } + + public override CommandResult Execute(IEnumerable args) + { + List newArgs = ["package", "list"]; + if (!string.IsNullOrEmpty(_projectName)) + { + newArgs.Add("--project"); + newArgs.Add(_projectName); + } + newArgs.AddRange(args); + + return base.Execute(newArgs); + } + + public PackageListCommand WithProject(string projectName) + { + _projectName = projectName; + return this; + } + } +} diff --git a/test/dotnet-completions.Tests/snapshots/bash/DotnetCliSnapshotTests.VerifyCompletions.verified.sh b/test/dotnet-completions.Tests/snapshots/bash/DotnetCliSnapshotTests.VerifyCompletions.verified.sh index 9a4a003fe1d0..44dc106b1abb 100644 --- a/test/dotnet-completions.Tests/snapshots/bash/DotnetCliSnapshotTests.VerifyCompletions.verified.sh +++ b/test/dotnet-completions.Tests/snapshots/bash/DotnetCliSnapshotTests.VerifyCompletions.verified.sh @@ -1083,7 +1083,7 @@ _testhost_package_list() { prev="${COMP_WORDS[COMP_CWORD-1]}" COMPREPLY=() - opts="--verbosity --outdated --deprecated --vulnerable --framework --include-transitive --include-prerelease --highest-patch --highest-minor --config --source --interactive --format --output-version --project --help" + opts="--verbosity --outdated --deprecated --vulnerable --framework --include-transitive --include-prerelease --highest-patch --highest-minor --config --source --interactive --format --output-version --no-restore --project --help" if [[ $COMP_CWORD == "$1" ]]; then COMPREPLY=( $(compgen -W "$opts" -- "$cur") ) @@ -2224,4 +2224,4 @@ _testhost_completions_script() { -complete -F _testhost testhost \ No newline at end of file +complete -F _testhost testhost diff --git a/test/dotnet-completions.Tests/snapshots/pwsh/DotnetCliSnapshotTests.VerifyCompletions.verified.ps1 b/test/dotnet-completions.Tests/snapshots/pwsh/DotnetCliSnapshotTests.VerifyCompletions.verified.ps1 index b8ba20263713..6671e9e5e7be 100644 --- a/test/dotnet-completions.Tests/snapshots/pwsh/DotnetCliSnapshotTests.VerifyCompletions.verified.ps1 +++ b/test/dotnet-completions.Tests/snapshots/pwsh/DotnetCliSnapshotTests.VerifyCompletions.verified.ps1 @@ -637,6 +637,7 @@ Register-ArgumentCompleter -Native -CommandName 'testhost' -ScriptBlock { [CompletionResult]::new('--format', '--format', [CompletionResultType]::ParameterName, "Specifies the output format type for the list packages command.") [CompletionResult]::new('--output-version', '--output-version', [CompletionResultType]::ParameterName, "Specifies the version of machine-readable output. Requires the `'--format json`' option.") [CompletionResult]::new('--project', '--project', [CompletionResultType]::ParameterName, "The project file to operate on. If a file is not specified, the command will search the current directory for one.") + [CompletionResult]::new('--no-restore', '--no-restore', [CompletionResultType]::ParameterName, "Do not restore before running the command.") [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, "Show command line help.") [CompletionResult]::new('--help', '-h', [CompletionResultType]::ParameterName, "Show command line help.") ) diff --git a/test/dotnet-completions.Tests/snapshots/zsh/DotnetCliSnapshotTests.VerifyCompletions.verified.zsh b/test/dotnet-completions.Tests/snapshots/zsh/DotnetCliSnapshotTests.VerifyCompletions.verified.zsh index 451a9b00d108..a56b37839ce8 100644 --- a/test/dotnet-completions.Tests/snapshots/zsh/DotnetCliSnapshotTests.VerifyCompletions.verified.zsh +++ b/test/dotnet-completions.Tests/snapshots/zsh/DotnetCliSnapshotTests.VerifyCompletions.verified.zsh @@ -630,6 +630,7 @@ _testhost() { '--format=[Specifies the output format type for the list packages command.]: :((console\:"console" json\:"json" ))' \ '--output-version=[Specifies the version of machine-readable output. Requires the '\''--format json'\'' option.]: : ' \ '--project=[The project file to operate on. If a file is not specified, the command will search the current directory for one.]: : ' \ + '--no-restore[Do not restore before running the command.]' \ '--help[Show command line help.]' \ '-h[Show command line help.]' \ && ret=0 diff --git a/test/dotnet-list-package.Tests/GivenDotnetListPackage.cs b/test/dotnet-list-package.Tests/GivenDotnetListPackage.cs index 4e0be90d99ca..060e6fa5874f 100644 --- a/test/dotnet-list-package.Tests/GivenDotnetListPackage.cs +++ b/test/dotnet-list-package.Tests/GivenDotnetListPackage.cs @@ -139,12 +139,30 @@ public void AssetsPathExistsButNotRestored() new ListPackageCommand(Log) .WithWorkingDirectory(projectDirectory) - .Execute() + .Execute("--no-restore") .Should() .Fail() .And.HaveStdErr(); } + [Fact] + public void RestoresAndLists() + { + var testAsset = "NewtonSoftDependentProject"; + var projectDirectory = _testAssetsManager + .CopyTestAsset(testAsset) + .WithSource() + .Path; + + new PackageListCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute() + .Should() + .Pass() + .And.HaveStdOut() + .And.HaveStdOutContaining("NewtonSoft.Json"); + } + [Fact] public void ItListsTransitivePackage() { diff --git a/test/dotnet.Tests/dotnet-pacakge-list/GivenDotnetPackageList.cs b/test/dotnet.Tests/dotnet-pacakge-list/GivenDotnetPackageList.cs new file mode 100644 index 000000000000..b9915dfd4326 --- /dev/null +++ b/test/dotnet.Tests/dotnet-pacakge-list/GivenDotnetPackageList.cs @@ -0,0 +1,460 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +#nullable disable + +using Microsoft.DotNet.Cli.Utils; +using Microsoft.DotNet.Tools.Package.List; + +namespace Microsoft.DotNet.Cli.Package.List.Tests +{ + public class GivenDotnetPackageList : SdkTest + { + public GivenDotnetPackageList(ITestOutputHelper output) : base(output) + { + } + + [Fact] + public void ItShowsCoreOutputOnMinimalVerbosity() + { + var testAssetName = "NewtonSoftDependentProject"; + var testAsset = _testAssetsManager + .CopyTestAsset(testAssetName) + .WithSource(); + var projectDirectory = testAsset.Path; + + new RestoreCommand(testAsset) + .Execute() + .Should() + .Pass() + .And.NotHaveStdErr(); + + new PackageListCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute("--verbosity", "quiet", "--no-restore") + .Should() + .Pass() + .And.NotHaveStdErr() + .And.HaveStdOutContaining("NewtonSoft.Json"); + } + + [Fact] + public void RequestedAndResolvedVersionsMatch() + { + var testAssetName = "TestAppSimple"; + var testAsset = _testAssetsManager + .CopyTestAsset(testAssetName) + .WithSource(); + + var projectDirectory = testAsset.Path; + + var packageName = "Newtonsoft.Json"; + var packageVersion = ToolsetInfo.GetNewtonsoftJsonPackageVersion(); + var cmd = new DotnetCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute("add", "package", packageName, "--version", packageVersion); + cmd.Should().Pass(); + + new RestoreCommand(testAsset) + .Execute() + .Should() + .Pass() + .And.NotHaveStdErr(); + + new PackageListCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute("--no-restore") + .Should() + .Pass() + .And.NotHaveStdErr() + .And.HaveStdOutContainingIgnoreSpaces(packageName + packageVersion + packageVersion); + } + + [Fact] + public void ItListsAutoReferencedPackages() + { + var testAssetName = "TestAppSimple"; + var testAsset = _testAssetsManager + .CopyTestAsset(testAssetName) + .WithSource() + .WithProjectChanges(ChangeTargetFrameworkTo2_1); + var projectDirectory = testAsset.Path; + + new RestoreCommand(testAsset) + .Execute() + .Should() + .Pass() + .And.NotHaveStdErr(); + + new PackageListCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute("--no-restore") + .Should() + .Pass() + .And.NotHaveStdErr() + .And.HaveStdOutContainingIgnoreSpaces("Microsoft.NETCore.App(A)") + .And.HaveStdOutContainingIgnoreSpaces("(A):Auto-referencedpackage"); + + static void ChangeTargetFrameworkTo2_1(XDocument project) + { + project.Descendants() + .Single(e => e.Name.LocalName == "TargetFramework") + .Value = "netcoreapp2.1"; + } + } + + [Fact] + public void ItRunOnSolution() + { + var sln = "TestAppWithSlnAndSolutionFolders"; + var testAsset = _testAssetsManager + .CopyTestAsset(sln) + .WithSource(); + var projectDirectory = testAsset.Path; + + new RestoreCommand(testAsset, "App.sln") + .Execute() + .Should() + .Pass() + .And.NotHaveStdErr(); + + new PackageListCommand(Log) + .WithProject("App.sln") + .WithWorkingDirectory(projectDirectory) + .Execute("--no-restore") + .Should() + .Pass() + .And.NotHaveStdErr() + .And.HaveStdOutContainingIgnoreSpaces("NewtonSoft.Json"); + } + + [Fact] + public void AssetsPathExistsButNotRestored() + { + var testAsset = "NewtonSoftDependentProject"; + var projectDirectory = _testAssetsManager + .CopyTestAsset(testAsset) + .WithSource() + .Path; + + new PackageListCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute("--no-restore") + .Should() + .Fail() + .And.HaveStdErr(); + } + + + [Fact] + public void RestoresAndLists() + { + var testAsset = "NewtonSoftDependentProject"; + var projectDirectory = _testAssetsManager + .CopyTestAsset(testAsset) + .WithSource() + .Path; + + new PackageListCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute() + .Should() + .Pass() + .And.HaveStdOut() + .And.HaveStdOutContaining("NewtonSoft.Json"); + } + + [Fact] + public void ItListsTransitivePackage() + { + var testProject = new TestProject + { + Name = "NewtonSoftDependentProject", + TargetFrameworks = ToolsetInfo.CurrentTargetFramework, + IsExe = true, + SourceFiles = + { +["Program.cs"] = @" +using System; +using System.Collections; +using Newtonsoft.Json.Linq; + +class Program +{ + public static void Main(string[] args) + { + ArrayList argList = new ArrayList(args); + JObject jObject = new JObject(); + + foreach (string arg in argList) + { + jObject[arg] = arg; + } + Console.WriteLine(jObject.ToString()); + } +} +", + } + }; + + testProject.PackageReferences.Add(new TestPackageReference("NewtonSoft.Json", "9.0.1")); + + // Disable package pruning so that there are still transitive dependencies to test the command + testProject.AdditionalProperties["RestoreEnablePackagePruning"] = "false"; + + var testAsset = _testAssetsManager.CreateTestProject(testProject); + var projectDirectory = Path.Combine(testAsset.Path, testProject.Name); + + new RestoreCommand(testAsset) + .Execute() + .Should() + .Pass() + .And.NotHaveStdErr(); + + new PackageListCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute("--no-restore") + .Should() + .Pass() + .And.NotHaveStdErr() + .And.NotHaveStdOutContaining("System.IO.FileSystem"); + + new PackageListCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute(args: ["--include-transitive", "--no-restore"]) + .Should() + .Pass() + .And.NotHaveStdErr() + .And.HaveStdOutContaining("System.IO.FileSystem"); + } + + [Theory] + [InlineData("", "[net451]", null)] + [InlineData("", $"[{ToolsetInfo.CurrentTargetFramework}]", null)] + [InlineData($"--framework {ToolsetInfo.CurrentTargetFramework} --framework net451", "[net451]", null)] + [InlineData($"--framework {ToolsetInfo.CurrentTargetFramework} --framework net451", $"[{ToolsetInfo.CurrentTargetFramework}]", null)] + [InlineData($"--framework {ToolsetInfo.CurrentTargetFramework}", $"[{ToolsetInfo.CurrentTargetFramework}]", "[net451]")] + [InlineData("--framework net451", "[net451]", "[netcoreapp3.0]")] + [InlineData($"-f {ToolsetInfo.CurrentTargetFramework} -f net451", "[net451]", null)] + [InlineData($"-f {ToolsetInfo.CurrentTargetFramework} -f net451", $"[{ToolsetInfo.CurrentTargetFramework}]", null)] + [InlineData($"-f {ToolsetInfo.CurrentTargetFramework}", $"[{ToolsetInfo.CurrentTargetFramework}]", "[net451]")] + [InlineData("-f net451", "[net451]", "[netcoreapp3.0]")] + public void ItListsValidFrameworks(string args, string shouldInclude, string shouldntInclude) + { + var testAssetName = "MSBuildAppWithMultipleFrameworks"; + var testAsset = _testAssetsManager + .CopyTestAsset(testAssetName, identifier: args.GetHashCode().ToString() + shouldInclude) + .WithSource(); + var projectDirectory = testAsset.Path; + + new RestoreCommand(testAsset) + .Execute() + .Should() + .Pass() + .And.NotHaveStdErr(); + + if (shouldntInclude == null) + { + new PackageListCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute(args.Split(' ', options: StringSplitOptions.RemoveEmptyEntries)) + .Should() + .Pass() + .And.NotHaveStdErr() + .And.HaveStdOutContainingIgnoreSpaces(shouldInclude.Replace(" ", "")); + } + else + { + new PackageListCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute(args.Split(' ', options: StringSplitOptions.RemoveEmptyEntries)) + .Should() + .Pass() + .And.NotHaveStdErr() + .And.HaveStdOutContainingIgnoreSpaces(shouldInclude.Replace(" ", "")) + .And.NotHaveStdOutContaining(shouldntInclude.Replace(" ", "")); + } + + } + + [Fact] + public void ItDoesNotAcceptInvalidFramework() + { + var testAssetName = "MSBuildAppWithMultipleFrameworks"; + var testAsset = _testAssetsManager + .CopyTestAsset(testAssetName) + .WithSource(); + var projectDirectory = testAsset.Path; + + new RestoreCommand(testAsset) + .Execute() + .Should() + .Pass(); + + new PackageListCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute("--framework", "invalid") + .Should() + .Fail(); + } + + [FullMSBuildOnlyFact] + public void ItListsFSharpProject() + { + var testAssetName = "FSharpTestAppSimple"; + var testAsset = _testAssetsManager + .CopyTestAsset(testAssetName) + .WithSource(); + var projectDirectory = testAsset.Path; + + new RestoreCommand(testAsset) + .Execute() + .Should() + .Pass() + .And.NotHaveStdErr(); + + new PackageListCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute() + .Should() + .Pass() + .And.NotHaveStdErr(); + } + + [Theory] + [InlineData(false, "--no-restore")] + [InlineData(false, "--vulnerable")] + [InlineData(false, "--no-restore", "--include-transitive")] + [InlineData(false, "--no-restore", "--include-prerelease")] + [InlineData(false, "--no-restore", "--deprecated")] + [InlineData(false, "--no-restore", "--outdated")] + [InlineData(false, "--no-restore", "--vulnerable")] + [InlineData(false, "--vulnerable", "--include-transitive")] + [InlineData(false, "--vulnerable", "--include-prerelease")] + [InlineData(false, "--deprecated", "--highest-minor")] + [InlineData(false, "--deprecated", "--highest-patch")] + [InlineData(false, "--outdated", "--include-prerelease")] + [InlineData(false, "--outdated", "--highest-minor")] + [InlineData(false, "--outdated", "--highest-patch")] + [InlineData(false, "--config")] + [InlineData(false, "--configfile")] + [InlineData(false, "--source")] + [InlineData(false, "-s")] + [InlineData(false, "--config", "--deprecated")] + [InlineData(false, "--configfile", "--deprecated")] + [InlineData(false, "--source", "--vulnerable")] + [InlineData(false, "-s", "--vulnerable")] + [InlineData(true, "--vulnerable", "--deprecated")] + [InlineData(true, "--vulnerable", "--outdated")] + [InlineData(true, "--deprecated", "--outdated")] + public void ItEnforcesOptionRules(bool throws, params string[] options) + { + var parseResult = Parser.Instance.Parse($"dotnet package list {string.Join(' ', options)}"); + Action checkRules = () => ListPackageReferencesCommand.EnforceOptionRules(parseResult); + + if (throws) + { + Assert.Throws(checkRules); + } + else + { + checkRules(); // Test for no throw + } + } + + [UnixOnlyFact] + public void ItRunsInCurrentDirectoryWithPoundInPath() + { + // Regression test for https://github.com/dotnet/sdk/issues/19654 + var testAssetName = "TestAppSimple"; + var testAsset = _testAssetsManager + .CopyTestAsset(testAssetName, "C#") + .WithSource(); + var projectDirectory = testAsset.Path; + + new RestoreCommand(testAsset) + .Execute() + .Should() + .Pass(); + + new PackageListCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute() + .Should() + .Pass(); + } + + [Fact] + public void ItRecognizesRelativePathsForAProject() + { + var testAssetName = "TestAppSimple"; + var testAsset = _testAssetsManager + .CopyTestAsset(testAssetName) + .WithSource(); + + var projectDirectory = testAsset.Path; + + new RestoreCommand(testAsset) + .Execute() + .Should() + .Pass(); + + new PackageListCommand(Log) + .WithProject("TestAppSimple.csproj") + .WithWorkingDirectory(projectDirectory) + .Execute() + .Should() + .Pass(); + } + + [Fact] + public void ItRecognizesRelativePathsForASolution() + { + var sln = "TestAppWithSlnAndSolutionFolders"; + var testAsset = _testAssetsManager + .CopyTestAsset(sln) + .WithSource(); + + var projectDirectory = testAsset.Path; + + new RestoreCommand(testAsset, "App.sln") + .Execute() + .Should() + .Pass(); + + new PackageListCommand(Log) + .WithProject("App.sln") + .WithWorkingDirectory(projectDirectory) + .Execute() + .Should() + .Pass(); + } + + [Fact] + public void ItRecognizesRelativePathsForASolutionFromSubFolder() + { + var sln = "TestAppWithSlnAndSolutionFolders"; + var testAsset = _testAssetsManager + .CopyTestAsset(sln) + .WithSource(); + + var projectDirectory = testAsset.Path; + + string subFolderName = "subFolder"; + var subFolderPath = Path.Combine(projectDirectory, subFolderName); + Directory.CreateDirectory(subFolderPath); + + new RestoreCommand(testAsset, "App.sln") + .Execute() + .Should() + .Pass(); + + new PackageListCommand(Log) + .WithProject("../App.sln") + .WithWorkingDirectory(subFolderPath) + .Execute() + .Should() + .Pass(); + } + } +} diff --git a/test/dotnet.Tests/dotnet.Tests.csproj b/test/dotnet.Tests/dotnet.Tests.csproj index b242b6f20c07..00427dd42924 100644 --- a/test/dotnet.Tests/dotnet.Tests.csproj +++ b/test/dotnet.Tests/dotnet.Tests.csproj @@ -39,6 +39,7 @@ + From 09e937664053649406376c2584a2fc1730a91a20 Mon Sep 17 00:00:00 2001 From: Nigusu Yenework Date: Tue, 25 Mar 2025 09:55:48 -0700 Subject: [PATCH 02/13] else --- src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs index 5d6371ab800e..d62cfde53527 100644 --- a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs +++ b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs @@ -77,8 +77,10 @@ private int RunRestore(string projectOrSolution, ReportOutputFormat formatOption "}"; Console.WriteLine(jsonError); } - - Console.WriteLine(String.Format(CultureInfo.CurrentCulture, LocalizableStrings.Error_restore)); + else + { + Console.WriteLine(String.Format(CultureInfo.CurrentCulture, LocalizableStrings.Error_restore)); + } } return exitCode; From 238d067317576f1025be5856693e5a35af6757b5 Mon Sep 17 00:00:00 2001 From: Nigusu Solomon Yenework <59111203+Nigusu-Allehu@users.noreply.github.com> Date: Tue, 25 Mar 2025 10:10:29 -0700 Subject: [PATCH 03/13] undo --- src/Cli/dotnet/Properties/launchSettings.json | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/Cli/dotnet/Properties/launchSettings.json b/src/Cli/dotnet/Properties/launchSettings.json index dc5cb018fd9c..facffd64a35f 100644 --- a/src/Cli/dotnet/Properties/launchSettings.json +++ b/src/Cli/dotnet/Properties/launchSettings.json @@ -1,9 +1,7 @@ { "profiles": { "dotnet": { - "commandName": "Project", - "commandLineArgs": "package list --format json", - "workingDirectory": "N:\\trash\\p7\\p7" + "commandName": "Project" } } -} \ No newline at end of file +} From 5f114bf12346b7c1aa67cf5d02eb4095b168684d Mon Sep 17 00:00:00 2001 From: Nigusu Yenework Date: Tue, 25 Mar 2025 15:01:36 -0700 Subject: [PATCH 04/13] use string literals --- .../Package/List/PackageListCommand.cs | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs index d62cfde53527..4c4735087efe 100644 --- a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs +++ b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs @@ -65,16 +65,17 @@ private int RunRestore(string projectOrSolution, ReportOutputFormat formatOption { if (formatOption == ReportOutputFormat.json) { - string jsonError = - "{\r\n" + - " \"version\": 1,\r\n" + - " \"problems\": [\r\n" + - " {\r\n" + - $" \"text\": \"{String.Format(CultureInfo.CurrentCulture, LocalizableStrings.Error_restore)}\",\r\n" + - " \"level\": \"error\"\r\n" + - " }\r\n" + - " ]\r\n" + - "}"; + string jsonError = $$""" +{ + "version": 1, + "problems": [ + { + "text": "{{String.Format(CultureInfo.CurrentCulture, LocalizableStrings.Error_restore)}}", + "level": "error" + } + ] +} +"""; Console.WriteLine(jsonError); } else From 68c207080a7b684e5157e346ceb22b14978ea565 Mon Sep 17 00:00:00 2001 From: Nigusu Yenework Date: Wed, 26 Mar 2025 11:31:51 -0700 Subject: [PATCH 05/13] log restore progress for --format console --- .../Package/List/PackageListCommand.cs | 26 ++++++++++++++----- .../Package/List/PackageListCommandParser.cs | 1 + src/Cli/dotnet/Properties/launchSettings.json | 6 +++-- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs index 4c4735087efe..d951761d1fbf 100644 --- a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs +++ b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs @@ -38,7 +38,8 @@ public override int Execute() if (!noRestore) { ReportOutputFormat formatOption = _parseResult.GetValue((CliOption)PackageListCommandParser.FormatOption); - restoreExitCode = RunRestore(projectFile, formatOption); + bool interactive = _parseResult.GetValue((CliOption)PackageListCommandParser.InteractiveOption); + restoreExitCode = RunRestore(projectFile, formatOption, interactive); } return restoreExitCode == 0 @@ -46,9 +47,24 @@ public override int Execute() : restoreExitCode; } - private int RunRestore(string projectOrSolution, ReportOutputFormat formatOption) + private int RunRestore(string projectOrSolution, ReportOutputFormat formatOption, bool interactive) { - MSBuildForwardingApp restoringCommand = new MSBuildForwardingApp(argsToForward: ["-target:restore", projectOrSolution, "-noConsoleLogger"]); + List args; + + if (formatOption == ReportOutputFormat.json) + { + args = ["-target:restore", projectOrSolution, "-noConsoleLogger"]; + } + else + { + args = ["-target:restore", projectOrSolution, "--consoleLoggerParameters:Verbosity=Minimal;NoSummary"]; + } + + if (interactive) + { + args.Add("-interactive:true"); + } + MSBuildForwardingApp restoringCommand = new MSBuildForwardingApp(argsToForward: args); int exitCode = 0; @@ -78,10 +94,6 @@ private int RunRestore(string projectOrSolution, ReportOutputFormat formatOption """; Console.WriteLine(jsonError); } - else - { - Console.WriteLine(String.Format(CultureInfo.CurrentCulture, LocalizableStrings.Error_restore)); - } } return exitCode; diff --git a/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs b/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs index c5f4437e86d9..c20050dc5101 100644 --- a/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs +++ b/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs @@ -119,6 +119,7 @@ private static CliCommand ConstructCommand() command.Options.Add(InteractiveOption); command.Options.Add(FormatOption); command.Options.Add(OutputVersionOption); + command.Options.Add(NoRestore); command.Options.Add(PackageCommandParser.ProjectOption); command.SetAction((parseResult) => new PackageListCommand(parseResult).Execute()); diff --git a/src/Cli/dotnet/Properties/launchSettings.json b/src/Cli/dotnet/Properties/launchSettings.json index facffd64a35f..e306312be127 100644 --- a/src/Cli/dotnet/Properties/launchSettings.json +++ b/src/Cli/dotnet/Properties/launchSettings.json @@ -1,7 +1,9 @@ { "profiles": { "dotnet": { - "commandName": "Project" + "commandName": "Project", + "commandLineArgs": "package list p7.csproj", + "workingDirectory": "N:\\trash\\p7\\p7" } } -} +} \ No newline at end of file From 82ccaefdd86b9228597dce14a5f8e9f76f843232 Mon Sep 17 00:00:00 2001 From: Nigusu Solomon Yenework <59111203+Nigusu-Allehu@users.noreply.github.com> Date: Wed, 26 Mar 2025 13:51:00 -0700 Subject: [PATCH 06/13] undo --- src/Cli/dotnet/Properties/launchSettings.json | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/Cli/dotnet/Properties/launchSettings.json b/src/Cli/dotnet/Properties/launchSettings.json index e306312be127..e69de29bb2d1 100644 --- a/src/Cli/dotnet/Properties/launchSettings.json +++ b/src/Cli/dotnet/Properties/launchSettings.json @@ -1,9 +0,0 @@ -{ - "profiles": { - "dotnet": { - "commandName": "Project", - "commandLineArgs": "package list p7.csproj", - "workingDirectory": "N:\\trash\\p7\\p7" - } - } -} \ No newline at end of file From 3aefb6041b15195dce99aa2cab9c05cfbbcb1fd5 Mon Sep 17 00:00:00 2001 From: Nigusu Solomon Yenework <59111203+Nigusu-Allehu@users.noreply.github.com> Date: Wed, 26 Mar 2025 13:51:56 -0700 Subject: [PATCH 07/13] undo --- src/Cli/dotnet/Properties/launchSettings.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Cli/dotnet/Properties/launchSettings.json b/src/Cli/dotnet/Properties/launchSettings.json index e69de29bb2d1..facffd64a35f 100644 --- a/src/Cli/dotnet/Properties/launchSettings.json +++ b/src/Cli/dotnet/Properties/launchSettings.json @@ -0,0 +1,7 @@ +{ + "profiles": { + "dotnet": { + "commandName": "Project" + } + } +} From e67eaa3ba15251d557626f606c4b49083de7f0c6 Mon Sep 17 00:00:00 2001 From: Nigusu Yenework Date: Fri, 28 Mar 2025 13:56:03 -0700 Subject: [PATCH 08/13] cleanup --- src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs index d951761d1fbf..aefbed60dfd7 100644 --- a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs +++ b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs @@ -49,15 +49,16 @@ public override int Execute() private int RunRestore(string projectOrSolution, ReportOutputFormat formatOption, bool interactive) { - List args; + List args = ["-target:Restore", projectOrSolution]; if (formatOption == ReportOutputFormat.json) { - args = ["-target:restore", projectOrSolution, "-noConsoleLogger"]; + args.Add("-noConsoleLogger"); } else { - args = ["-target:restore", projectOrSolution, "--consoleLoggerParameters:Verbosity=Minimal;NoSummary"]; + args.Add("-consoleLoggerParameters:NoSummary"); + args.Add("-verbosity:minimal"); } if (interactive) From 452b93cd27958533ba262a09cf0adb9564b63c46 Mon Sep 17 00:00:00 2001 From: Nigusu Solomon Yenework <59111203+Nigusu-Allehu@users.noreply.github.com> Date: Fri, 28 Mar 2025 16:05:59 -0700 Subject: [PATCH 09/13] false interactive --- src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs index aefbed60dfd7..c939dc18bd0e 100644 --- a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs +++ b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs @@ -65,7 +65,12 @@ private int RunRestore(string projectOrSolution, ReportOutputFormat formatOption { args.Add("-interactive:true"); } - MSBuildForwardingApp restoringCommand = new MSBuildForwardingApp(argsToForward: args); + else + { + args.Add("-interactive:false"); + } + + MSBuildForwardingApp restoringCommand = new MSBuildForwardingApp(argsToForward: args); int exitCode = 0; From c5f737f7a97e16710edb4f543c4ce46cea0e2463 Mon Sep 17 00:00:00 2001 From: Nigusu Yenework Date: Tue, 8 Apr 2025 14:37:15 -0700 Subject: [PATCH 10/13] merge main --- src/Cli/dotnet/Commands/CliCommandStrings.resx | 7 +++++++ .../Commands/Package/List/PackageListCommand.cs | 15 +++------------ .../Package/List/PackageListCommandParser.cs | 2 +- .../dotnet/Commands/xlf/CliCommandStrings.cs.xlf | 10 ++++++++++ .../dotnet/Commands/xlf/CliCommandStrings.de.xlf | 10 ++++++++++ .../dotnet/Commands/xlf/CliCommandStrings.es.xlf | 10 ++++++++++ .../dotnet/Commands/xlf/CliCommandStrings.fr.xlf | 10 ++++++++++ .../dotnet/Commands/xlf/CliCommandStrings.it.xlf | 10 ++++++++++ .../dotnet/Commands/xlf/CliCommandStrings.ja.xlf | 10 ++++++++++ .../dotnet/Commands/xlf/CliCommandStrings.ko.xlf | 10 ++++++++++ .../dotnet/Commands/xlf/CliCommandStrings.pl.xlf | 10 ++++++++++ .../Commands/xlf/CliCommandStrings.pt-BR.xlf | 10 ++++++++++ .../dotnet/Commands/xlf/CliCommandStrings.ru.xlf | 10 ++++++++++ .../dotnet/Commands/xlf/CliCommandStrings.tr.xlf | 10 ++++++++++ .../Commands/xlf/CliCommandStrings.zh-Hans.xlf | 10 ++++++++++ .../Commands/xlf/CliCommandStrings.zh-Hant.xlf | 10 ++++++++++ 16 files changed, 141 insertions(+), 13 deletions(-) diff --git a/src/Cli/dotnet/Commands/CliCommandStrings.resx b/src/Cli/dotnet/Commands/CliCommandStrings.resx index d18c552b8f74..7c44013e6890 100644 --- a/src/Cli/dotnet/Commands/CliCommandStrings.resx +++ b/src/Cli/dotnet/Commands/CliCommandStrings.resx @@ -483,6 +483,13 @@ This is equivalent to deleting project.assets.json. Specifies the version of machine-readable output. Requires the '--format json' option. + + Restore failed. Run `dotnet restore` for more details on the issue. + {Locked="dotnet restore"} + + + Do not restore before running the command. + PACKAGE_NAME diff --git a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs index c939dc18bd0e..619cfba7186b 100644 --- a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs +++ b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs @@ -6,12 +6,8 @@ using Microsoft.DotNet.Cli.Commands.NuGet; using Microsoft.DotNet.Cli.Extensions; using Microsoft.DotNet.Cli.Utils; -<<<<<<< HEAD:src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs -======= -using Microsoft.DotNet.Tools.NuGet; using System.Globalization; -using Microsoft.DotNet.Tools.MSBuild; ->>>>>>> 27439c5902 (dotnet list package restores):src/Cli/dotnet/Commands/Package/List/ListPackageReferencesCommand.cs +using Microsoft.DotNet.Cli.Commands.MSBuild; namespace Microsoft.DotNet.Cli.Commands.Package.List; @@ -92,7 +88,7 @@ private int RunRestore(string projectOrSolution, ReportOutputFormat formatOption "version": 1, "problems": [ { - "text": "{{String.Format(CultureInfo.CurrentCulture, LocalizableStrings.Error_restore)}}", + "text": "{{String.Format(CultureInfo.CurrentCulture, CliCommandStrings.Error_restore)}}", "level": "error" } ] @@ -123,14 +119,9 @@ private string[] TransformArgs(string projectOrSolution) { "package", "list", - GetProjectOrSolution() + projectOrSolution }; -<<<<<<< HEAD:src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs -======= - args.Add(projectOrSolution); - ->>>>>>> 27439c5902 (dotnet list package restores):src/Cli/dotnet/Commands/Package/List/ListPackageReferencesCommand.cs args.AddRange(_parseResult.OptionValuesToBeForwarded(PackageListCommandParser.GetCommand())); EnforceOptionRules(_parseResult); diff --git a/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs b/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs index c20050dc5101..88904d6de15a 100644 --- a/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs +++ b/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs @@ -74,7 +74,7 @@ internal static class PackageListCommandParser public static readonly CliOption NoRestore = new CliOption("--no-restore") { - Description = LocalizableStrings.CmdNoRestoreDescription, + Description = CliCommandStrings.CmdNoRestoreDescription, Arity = ArgumentArity.Zero }; diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf index b40213fe208b..28c05970ec5d 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.cs.xlf @@ -561,6 +561,11 @@ This is equivalent to deleting project.assets.json. Specify a project or solution file. The current working directory does not contain a project or solution file. + + Do not restore before running the command. + Do not restore before running the command. + + No test modules found for the given test module pattern: {0} with root directory: {1} No test modules found for the given test module pattern: {0} with root directory: {1} @@ -1061,6 +1066,11 @@ Make the profile names distinct. Make the profile names distinct. + + Restore failed. Run `dotnet restore` for more details on the issue. + Restore failed. Run `dotnet restore` for more details on the issue. + {Locked="dotnet restore"} + Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf index 084d78a04136..6934ad07dc21 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.de.xlf @@ -561,6 +561,11 @@ This is equivalent to deleting project.assets.json. Specify a project or solution file. The current working directory does not contain a project or solution file. + + Do not restore before running the command. + Do not restore before running the command. + + No test modules found for the given test module pattern: {0} with root directory: {1} No test modules found for the given test module pattern: {0} with root directory: {1} @@ -1061,6 +1066,11 @@ Make the profile names distinct. Make the profile names distinct. + + Restore failed. Run `dotnet restore` for more details on the issue. + Restore failed. Run `dotnet restore` for more details on the issue. + {Locked="dotnet restore"} + Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf index b52aee8f86dc..986040944a9a 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.es.xlf @@ -561,6 +561,11 @@ This is equivalent to deleting project.assets.json. Specify a project or solution file. The current working directory does not contain a project or solution file. + + Do not restore before running the command. + Do not restore before running the command. + + No test modules found for the given test module pattern: {0} with root directory: {1} No test modules found for the given test module pattern: {0} with root directory: {1} @@ -1061,6 +1066,11 @@ Make the profile names distinct. Make the profile names distinct. + + Restore failed. Run `dotnet restore` for more details on the issue. + Restore failed. Run `dotnet restore` for more details on the issue. + {Locked="dotnet restore"} + Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf index 15a358999121..699e27cf1172 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.fr.xlf @@ -561,6 +561,11 @@ This is equivalent to deleting project.assets.json. Specify a project or solution file. The current working directory does not contain a project or solution file. + + Do not restore before running the command. + Do not restore before running the command. + + No test modules found for the given test module pattern: {0} with root directory: {1} No test modules found for the given test module pattern: {0} with root directory: {1} @@ -1061,6 +1066,11 @@ Make the profile names distinct. Make the profile names distinct. + + Restore failed. Run `dotnet restore` for more details on the issue. + Restore failed. Run `dotnet restore` for more details on the issue. + {Locked="dotnet restore"} + Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf index 89c2748bdcb5..2e5547ff20df 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.it.xlf @@ -561,6 +561,11 @@ This is equivalent to deleting project.assets.json. Specify a project or solution file. The current working directory does not contain a project or solution file. + + Do not restore before running the command. + Do not restore before running the command. + + No test modules found for the given test module pattern: {0} with root directory: {1} No test modules found for the given test module pattern: {0} with root directory: {1} @@ -1061,6 +1066,11 @@ Make the profile names distinct. Make the profile names distinct. + + Restore failed. Run `dotnet restore` for more details on the issue. + Restore failed. Run `dotnet restore` for more details on the issue. + {Locked="dotnet restore"} + Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf index 101a5ec62e38..195f49f4dbf7 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ja.xlf @@ -561,6 +561,11 @@ This is equivalent to deleting project.assets.json. Specify a project or solution file. The current working directory does not contain a project or solution file. + + Do not restore before running the command. + Do not restore before running the command. + + No test modules found for the given test module pattern: {0} with root directory: {1} No test modules found for the given test module pattern: {0} with root directory: {1} @@ -1061,6 +1066,11 @@ Make the profile names distinct. Make the profile names distinct. + + Restore failed. Run `dotnet restore` for more details on the issue. + Restore failed. Run `dotnet restore` for more details on the issue. + {Locked="dotnet restore"} + Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf index f9ae5c299e5b..ada8d1ee5139 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ko.xlf @@ -561,6 +561,11 @@ This is equivalent to deleting project.assets.json. Specify a project or solution file. The current working directory does not contain a project or solution file. + + Do not restore before running the command. + Do not restore before running the command. + + No test modules found for the given test module pattern: {0} with root directory: {1} No test modules found for the given test module pattern: {0} with root directory: {1} @@ -1061,6 +1066,11 @@ Make the profile names distinct. Make the profile names distinct. + + Restore failed. Run `dotnet restore` for more details on the issue. + Restore failed. Run `dotnet restore` for more details on the issue. + {Locked="dotnet restore"} + Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf index 33642773ddff..d6df366369c5 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pl.xlf @@ -561,6 +561,11 @@ This is equivalent to deleting project.assets.json. Specify a project or solution file. The current working directory does not contain a project or solution file. + + Do not restore before running the command. + Do not restore before running the command. + + No test modules found for the given test module pattern: {0} with root directory: {1} No test modules found for the given test module pattern: {0} with root directory: {1} @@ -1061,6 +1066,11 @@ Make the profile names distinct. Make the profile names distinct. + + Restore failed. Run `dotnet restore` for more details on the issue. + Restore failed. Run `dotnet restore` for more details on the issue. + {Locked="dotnet restore"} + Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf index 5e076eb7a4f4..d90cb2c746d3 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.pt-BR.xlf @@ -561,6 +561,11 @@ This is equivalent to deleting project.assets.json. Specify a project or solution file. The current working directory does not contain a project or solution file. + + Do not restore before running the command. + Do not restore before running the command. + + No test modules found for the given test module pattern: {0} with root directory: {1} No test modules found for the given test module pattern: {0} with root directory: {1} @@ -1061,6 +1066,11 @@ Make the profile names distinct. Make the profile names distinct. + + Restore failed. Run `dotnet restore` for more details on the issue. + Restore failed. Run `dotnet restore` for more details on the issue. + {Locked="dotnet restore"} + Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf index 79dee0e34032..5105335f3ce0 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.ru.xlf @@ -561,6 +561,11 @@ This is equivalent to deleting project.assets.json. Specify a project or solution file. The current working directory does not contain a project or solution file. + + Do not restore before running the command. + Do not restore before running the command. + + No test modules found for the given test module pattern: {0} with root directory: {1} No test modules found for the given test module pattern: {0} with root directory: {1} @@ -1061,6 +1066,11 @@ Make the profile names distinct. Make the profile names distinct. + + Restore failed. Run `dotnet restore` for more details on the issue. + Restore failed. Run `dotnet restore` for more details on the issue. + {Locked="dotnet restore"} + Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf index b88fbaf94bbe..b4cf621b2847 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.tr.xlf @@ -561,6 +561,11 @@ This is equivalent to deleting project.assets.json. Specify a project or solution file. The current working directory does not contain a project or solution file. + + Do not restore before running the command. + Do not restore before running the command. + + No test modules found for the given test module pattern: {0} with root directory: {1} No test modules found for the given test module pattern: {0} with root directory: {1} @@ -1061,6 +1066,11 @@ Make the profile names distinct. Make the profile names distinct. + + Restore failed. Run `dotnet restore` for more details on the issue. + Restore failed. Run `dotnet restore` for more details on the issue. + {Locked="dotnet restore"} + Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf index d5a469a80b1a..bf305c614a41 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hans.xlf @@ -561,6 +561,11 @@ This is equivalent to deleting project.assets.json. Specify a project or solution file. The current working directory does not contain a project or solution file. + + Do not restore before running the command. + Do not restore before running the command. + + No test modules found for the given test module pattern: {0} with root directory: {1} No test modules found for the given test module pattern: {0} with root directory: {1} @@ -1061,6 +1066,11 @@ Make the profile names distinct. Make the profile names distinct. + + Restore failed. Run `dotnet restore` for more details on the issue. + Restore failed. Run `dotnet restore` for more details on the issue. + {Locked="dotnet restore"} + Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. diff --git a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf index a8ac9272ab9d..97dc514087ec 100644 --- a/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf +++ b/src/Cli/dotnet/Commands/xlf/CliCommandStrings.zh-Hant.xlf @@ -561,6 +561,11 @@ This is equivalent to deleting project.assets.json. Specify a project or solution file. The current working directory does not contain a project or solution file. + + Do not restore before running the command. + Do not restore before running the command. + + No test modules found for the given test module pattern: {0} with root directory: {1} No test modules found for the given test module pattern: {0} with root directory: {1} @@ -1061,6 +1066,11 @@ Make the profile names distinct. Make the profile names distinct. + + Restore failed. Run `dotnet restore` for more details on the issue. + Restore failed. Run `dotnet restore` for more details on the issue. + {Locked="dotnet restore"} + Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. Require that the search term exactly match the name of the package. Causes `--take` and `--skip` options to be ignored. From e2b69e2e3b94345ad243ecb39641a441d927d5d5 Mon Sep 17 00:00:00 2001 From: Nigusu Yenework Date: Tue, 8 Apr 2025 15:25:12 -0700 Subject: [PATCH 11/13] resolve conflict --- test/dotnet-list-package.Tests/GivenDotnetListPackage.cs | 4 ++-- .../dotnet-pacakge-list/GivenDotnetPackageList.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) rename test/{dotnet.Tests => }/dotnet-pacakge-list/GivenDotnetPackageList.cs (99%) diff --git a/test/dotnet-list-package.Tests/GivenDotnetListPackage.cs b/test/dotnet-list-package.Tests/GivenDotnetListPackage.cs index 060e6fa5874f..bef15fa249b4 100644 --- a/test/dotnet-list-package.Tests/GivenDotnetListPackage.cs +++ b/test/dotnet-list-package.Tests/GivenDotnetListPackage.cs @@ -154,7 +154,7 @@ public void RestoresAndLists() .WithSource() .Path; - new PackageListCommand(Log) + new ListPackageCommand(Log) .WithWorkingDirectory(projectDirectory) .Execute() .Should() @@ -343,7 +343,7 @@ public void ItListsFSharpProject() public void ItEnforcesOptionRules(bool throws, params string[] options) { var parseResult = Parser.Instance.Parse($"dotnet list package {string.Join(' ', options)}"); - Action checkRules = () => PackageListCommand.EnforceOptionRules(parseResult); + Action checkRules = () => Microsoft.DotNet.Cli.Commands.Package.List.PackageListCommand.EnforceOptionRules(parseResult); if (throws) { diff --git a/test/dotnet.Tests/dotnet-pacakge-list/GivenDotnetPackageList.cs b/test/dotnet-pacakge-list/GivenDotnetPackageList.cs similarity index 99% rename from test/dotnet.Tests/dotnet-pacakge-list/GivenDotnetPackageList.cs rename to test/dotnet-pacakge-list/GivenDotnetPackageList.cs index b9915dfd4326..54c06652ec0f 100644 --- a/test/dotnet.Tests/dotnet-pacakge-list/GivenDotnetPackageList.cs +++ b/test/dotnet-pacakge-list/GivenDotnetPackageList.cs @@ -6,7 +6,7 @@ using Microsoft.DotNet.Cli.Utils; using Microsoft.DotNet.Tools.Package.List; -namespace Microsoft.DotNet.Cli.Package.List.Tests +namespace Microsoft.DotNet.Cli.Commands.Package.List.Tests { public class GivenDotnetPackageList : SdkTest { From 1a39768814e5ae2a6d131d21531230cd136aab2b Mon Sep 17 00:00:00 2001 From: Nigusu Yenework Date: Tue, 8 Apr 2025 16:31:53 -0700 Subject: [PATCH 12/13] resolve completetion --- .../pwsh/DotnetCliSnapshotTests.VerifyCompletions.verified.ps1 | 2 +- .../zsh/DotnetCliSnapshotTests.VerifyCompletions.verified.zsh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/dotnet-completions.Tests/snapshots/pwsh/DotnetCliSnapshotTests.VerifyCompletions.verified.ps1 b/test/dotnet-completions.Tests/snapshots/pwsh/DotnetCliSnapshotTests.VerifyCompletions.verified.ps1 index 6671e9e5e7be..5433aad3fe93 100644 --- a/test/dotnet-completions.Tests/snapshots/pwsh/DotnetCliSnapshotTests.VerifyCompletions.verified.ps1 +++ b/test/dotnet-completions.Tests/snapshots/pwsh/DotnetCliSnapshotTests.VerifyCompletions.verified.ps1 @@ -636,8 +636,8 @@ Register-ArgumentCompleter -Native -CommandName 'testhost' -ScriptBlock { [CompletionResult]::new('--interactive', '--interactive', [CompletionResultType]::ParameterName, "Allows the command to stop and wait for user input or action (for example to complete authentication).") [CompletionResult]::new('--format', '--format', [CompletionResultType]::ParameterName, "Specifies the output format type for the list packages command.") [CompletionResult]::new('--output-version', '--output-version', [CompletionResultType]::ParameterName, "Specifies the version of machine-readable output. Requires the `'--format json`' option.") - [CompletionResult]::new('--project', '--project', [CompletionResultType]::ParameterName, "The project file to operate on. If a file is not specified, the command will search the current directory for one.") [CompletionResult]::new('--no-restore', '--no-restore', [CompletionResultType]::ParameterName, "Do not restore before running the command.") + [CompletionResult]::new('--project', '--project', [CompletionResultType]::ParameterName, "The project file to operate on. If a file is not specified, the command will search the current directory for one.") [CompletionResult]::new('--help', '--help', [CompletionResultType]::ParameterName, "Show command line help.") [CompletionResult]::new('--help', '-h', [CompletionResultType]::ParameterName, "Show command line help.") ) diff --git a/test/dotnet-completions.Tests/snapshots/zsh/DotnetCliSnapshotTests.VerifyCompletions.verified.zsh b/test/dotnet-completions.Tests/snapshots/zsh/DotnetCliSnapshotTests.VerifyCompletions.verified.zsh index a56b37839ce8..5795644bd951 100644 --- a/test/dotnet-completions.Tests/snapshots/zsh/DotnetCliSnapshotTests.VerifyCompletions.verified.zsh +++ b/test/dotnet-completions.Tests/snapshots/zsh/DotnetCliSnapshotTests.VerifyCompletions.verified.zsh @@ -629,8 +629,8 @@ _testhost() { '--interactive[Allows the command to stop and wait for user input or action (for example to complete authentication).]' \ '--format=[Specifies the output format type for the list packages command.]: :((console\:"console" json\:"json" ))' \ '--output-version=[Specifies the version of machine-readable output. Requires the '\''--format json'\'' option.]: : ' \ - '--project=[The project file to operate on. If a file is not specified, the command will search the current directory for one.]: : ' \ '--no-restore[Do not restore before running the command.]' \ + '--project=[The project file to operate on. If a file is not specified, the command will search the current directory for one.]: : ' \ '--help[Show command line help.]' \ '-h[Show command line help.]' \ && ret=0 From 1b792dc71df78efd0879311b142c9a3ae037b1c4 Mon Sep 17 00:00:00 2001 From: Nigusu Solomon Yenework <59111203+Nigusu-Allehu@users.noreply.github.com> Date: Tue, 8 Apr 2025 16:46:25 -0700 Subject: [PATCH 13/13] comment --- .../dotnet/Commands/Package/List/PackageListCommand.cs | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs index 619cfba7186b..04bbeffc7493 100644 --- a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs +++ b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs @@ -57,14 +57,7 @@ private int RunRestore(string projectOrSolution, ReportOutputFormat formatOption args.Add("-verbosity:minimal"); } - if (interactive) - { - args.Add("-interactive:true"); - } - else - { - args.Add("-interactive:false"); - } + args.Add($"-interactive:{interactive.ToString().ToLower()}"); MSBuildForwardingApp restoringCommand = new MSBuildForwardingApp(argsToForward: args);