diff --git a/src/Cli/dotnet/Commands/Hidden/List/Package/ListPackageCommandParser.cs b/src/Cli/dotnet/Commands/Hidden/List/Package/ListPackageCommandParser.cs index a1d8c613f289..c060d193996a 100644 --- a/src/Cli/dotnet/Commands/Hidden/List/Package/ListPackageCommandParser.cs +++ b/src/Cli/dotnet/Commands/Hidden/List/Package/ListPackageCommandParser.cs @@ -19,7 +19,12 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("package", CliCommandStrings.PackageListAppFullName); + Command command = new("package", CliCommandStrings.PackageListAppFullName) + { + // Allow unmatched tokens to support binlog arguments (e.g., --bl, -bl:output.binlog) + // that are forwarded to the MSBuild restore phase + TreatUnmatchedTokensAsErrors = false + }; command.Options.Add(PackageListCommandParser.VerbosityOption); command.Options.Add(PackageListCommandParser.OutdatedOption); diff --git a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs index 4ff46b804d2c..7501d4e52470 100644 --- a/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs +++ b/src/Cli/dotnet/Commands/Package/List/PackageListCommand.cs @@ -62,6 +62,15 @@ private int RunRestore(string projectOrSolution, ReportOutputFormat formatOption args.Add($"-interactive:{interactive.ToString().ToLower()}"); + // Forward any binlog arguments from the command line to the restore phase + foreach (var token in _parseResult.UnmatchedTokens) + { + if (LoggerUtility.IsBinLogArgument(token)) + { + args.Add(token); + } + } + MSBuildForwardingApp restoringCommand = new MSBuildForwardingApp(rawMSBuildArgs: args); int exitCode = 0; diff --git a/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs b/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs index 2ce93a3c7e80..826fe0c20f7a 100644 --- a/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs +++ b/src/Cli/dotnet/Commands/Package/List/PackageListCommandParser.cs @@ -105,7 +105,12 @@ public static Command GetCommand() private static Command ConstructCommand() { - Command command = new("list", CliCommandStrings.PackageListAppFullName); + Command command = new("list", CliCommandStrings.PackageListAppFullName) + { + // Allow unmatched tokens to support binlog arguments (e.g., --bl, -bl:output.binlog) + // that are forwarded to the MSBuild restore phase + TreatUnmatchedTokensAsErrors = false + }; command.Options.Add(VerbosityOption); command.Options.Add(OutdatedOption); diff --git a/test/dotnet.Tests/CommandTests/Package/List/GivenDotnetListPackage.cs b/test/dotnet.Tests/CommandTests/Package/List/GivenDotnetListPackage.cs index e0901d0a4b68..9dd1f8b4a93f 100644 --- a/test/dotnet.Tests/CommandTests/Package/List/GivenDotnetListPackage.cs +++ b/test/dotnet.Tests/CommandTests/Package/List/GivenDotnetListPackage.cs @@ -454,5 +454,33 @@ public void ItRecognizesRelativePathsForASolutionFromSubFolder() .Should() .Pass(); } + + [Fact] + public void ItAcceptsBinlogArgument() + { + var testAssetName = "TestAppSimple"; + var testAsset = _testAssetsManager + .CopyTestAsset(testAssetName) + .WithSource(); + + var projectDirectory = testAsset.Path; + var binlogPath = Path.Combine(projectDirectory, "restore.binlog"); + + // Ensure no binlog exists initially + if (File.Exists(binlogPath)) + { + File.Delete(binlogPath); + } + + // Run list package with binlog argument (restore will run and create binlog) + new ListPackageCommand(Log) + .WithWorkingDirectory(projectDirectory) + .Execute("-bl:" + binlogPath) + .Should() + .Pass(); + + // Verify binlog was created + File.Exists(binlogPath).Should().BeTrue("binlog file should be created during restore"); + } } }