From 0146202e77131e1bd1f59892cc8fcf0675d2f3a6 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Thu, 10 Apr 2025 10:31:50 -0500 Subject: [PATCH 1/3] fix defaults :-/ --- src/Cli/dotnet/CommonOptions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Cli/dotnet/CommonOptions.cs b/src/Cli/dotnet/CommonOptions.cs index bda8bdca8970..fe1d4c775e71 100644 --- a/src/Cli/dotnet/CommonOptions.cs +++ b/src/Cli/dotnet/CommonOptions.cs @@ -133,7 +133,7 @@ public static ForwardedOption InteractiveOption(bool acceptArgument = fals Description = CliStrings.CommandInteractiveOptionDescription, Arity = acceptArgument ? ArgumentArity.ZeroOrOne : ArgumentArity.Zero, // this default is called when no tokens/options are passed on the CLI args - DefaultValueFactory = (ar) => IsCIEnvironmentOrRedirected() + DefaultValueFactory = (ar) => !IsCIEnvironmentOrRedirected() }; public static CliOption InteractiveMsBuildForwardOption = InteractiveOption(acceptArgument: true).ForwardAsSingle(b => $"-property:NuGetInteractive={(b ? "true" : "false")}"); From fe3bd41936bee1916bdc8be6bd1e92b5b6c14891 Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Thu, 10 Apr 2025 12:10:46 -0500 Subject: [PATCH 2/3] fix a bunch of tests --- test/dotnet-watch.Tests/CommandLineOptionsTests.cs | 2 +- .../CommandTests/MSBuild/GivenDotnetBuildInvocation.cs | 2 +- .../CommandTests/MSBuild/GivenDotnetCleanInvocation.cs | 2 +- .../CommandTests/MSBuild/GivenDotnetOsArchOptions.cs | 2 +- .../CommandTests/MSBuild/GivenDotnetPackInvocation.cs | 2 +- .../CommandTests/MSBuild/GivenDotnetPublishInvocation.cs | 2 +- .../CommandTests/MSBuild/GivenDotnetRestoreInvocation.cs | 2 +- .../CommandTests/MSBuild/GivenDotnetRunInvocation.cs | 2 +- .../CommandTests/MSBuild/GivenDotnetTestInvocation.cs | 2 +- .../Package/Remove/GivenDotnetRemovePackage.cs | 2 +- .../Reference/Add/AddReferenceParserTests.cs | 9 --------- .../Reference/Add/GivenDotnetAddReference.cs | 2 +- 12 files changed, 11 insertions(+), 20 deletions(-) diff --git a/test/dotnet-watch.Tests/CommandLineOptionsTests.cs b/test/dotnet-watch.Tests/CommandLineOptionsTests.cs index 60a93026f998..996dd27370ca 100644 --- a/test/dotnet-watch.Tests/CommandLineOptionsTests.cs +++ b/test/dotnet-watch.Tests/CommandLineOptionsTests.cs @@ -414,7 +414,7 @@ public void ShortFormForLaunchProfileArgumentWorks() Assert.Equal("CustomLaunchProfile", options.LaunchProfileName); } - private const string NugetInteractiveProperty = "-property:NuGetInteractive=true"; + private const string NugetInteractiveProperty = "-property:NuGetInteractive=false"; /// /// Validates that options that the "run" command forwards to "build" command are forwarded by dotnet-watch. diff --git a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetBuildInvocation.cs b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetBuildInvocation.cs index e1ec4ba71e35..b16aa4f38288 100644 --- a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetBuildInvocation.cs +++ b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetBuildInvocation.cs @@ -10,7 +10,7 @@ public class GivenDotnetBuildInvocation : IClassFixture { - private const string NugetInteractiveProperty = "-property:NuGetInteractive=true"; + private const string NugetInteractiveProperty = "-property:NuGetInteractive=false"; private static readonly string[] ExpectedPrefix = ["-maxcpucount", "-verbosity:m", "-tlp:default=auto", "-nologo", "-verbosity:normal", "-target:Clean", NugetInteractiveProperty]; diff --git a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetOsArchOptions.cs b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetOsArchOptions.cs index 54a1ef267eee..efce58f982e5 100644 --- a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetOsArchOptions.cs +++ b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetOsArchOptions.cs @@ -14,7 +14,7 @@ public GivenDotnetOsArchOptions(ITestOutputHelper log) : base(log) } private static readonly string[] ExpectedPrefix = ["-maxcpucount", "-verbosity:m", "-tlp:default=auto", "-nologo"]; - private const string NugetInteractiveProperty = "-property:NuGetInteractive=true"; + private const string NugetInteractiveProperty = "-property:NuGetInteractive=false"; private static readonly string[] DefaultArgs = ["-restore", "-consoleloggerparameters:Summary", NugetInteractiveProperty]; private static readonly string WorkingDirectory = diff --git a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetPackInvocation.cs b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetPackInvocation.cs index 15a01f9b40a3..898ea5d9e9c7 100644 --- a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetPackInvocation.cs +++ b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetPackInvocation.cs @@ -10,7 +10,7 @@ public class GivenDotnetPackInvocation : IClassFixture { - private static readonly string[] ExpectedPrefix = ["-maxcpucount", "-verbosity:m", "-tlp:default=auto", "-nologo", "-target:Restore", "-property:NuGetInteractive=true"]; + private static readonly string[] ExpectedPrefix = ["-maxcpucount", "-verbosity:m", "-tlp:default=auto", "-nologo", "-target:Restore"]; private static readonly string WorkingDirectory = TestPathUtilities.FormatAbsolutePath(nameof(GivenDotnetRestoreInvocation)); diff --git a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRunInvocation.cs b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRunInvocation.cs index 1b2ac0950389..6b291ec53c76 100644 --- a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRunInvocation.cs +++ b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRunInvocation.cs @@ -8,7 +8,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [Collection(TestConstants.UsesStaticTelemetryState)] public class GivenDotnetRunInvocation : IClassFixture { - private static readonly string[] ConstantRestoreArgs = ["-nologo", "-verbosity:minimal", "-property:NuGetInteractive=true"]; + private static readonly string[] ConstantRestoreArgs = ["-nologo", "-verbosity:quiet"]; public ITestOutputHelper Log { get; } diff --git a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetTestInvocation.cs b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetTestInvocation.cs index b146ead52b80..30fce45eb55f 100644 --- a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetTestInvocation.cs +++ b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetTestInvocation.cs @@ -8,7 +8,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests [Collection(TestConstants.UsesStaticTelemetryState)] public class GivenDotnetTestInvocation : IClassFixture { - private static readonly string[] ExpectedPrefix = ["-maxcpucount", "-verbosity:m", "-tlp:default=auto", "-nologo", "-restore", "-nologo", "-target:VSTest", "-property:NuGetInteractive=true"]; + private static readonly string[] ExpectedPrefix = ["-maxcpucount", "-verbosity:m", "-tlp:default=auto", "-nologo", "-restore", "-nologo", "-target:VSTest", "-property:NuGetInteractive=false"]; private static readonly string WorkingDirectory = TestPathUtilities.FormatAbsolutePath(nameof(GivenDotnetTestInvocation)); diff --git a/test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetRemovePackage.cs b/test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetRemovePackage.cs index 9a94cfe86f97..059877551298 100644 --- a/test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetRemovePackage.cs +++ b/test/dotnet.Tests/CommandTests/Package/Remove/GivenDotnetRemovePackage.cs @@ -18,7 +18,7 @@ dotnet remove [] package ... [options] The package reference to remove. Options: - --interactive Allows the command to stop and wait for user input or action (for example to complete authentication). [default: True] + --interactive Allows the command to stop and wait for user input or action (for example to complete authentication). [default: False] -?, -h, --help Show command line help."; private Func RemoveCommandHelpText = (defaultVal) => $@"Description: diff --git a/test/dotnet.Tests/CommandTests/Reference/Add/AddReferenceParserTests.cs b/test/dotnet.Tests/CommandTests/Reference/Add/AddReferenceParserTests.cs index 20204cc1fa26..1efd8b75d6df 100644 --- a/test/dotnet.Tests/CommandTests/Reference/Add/AddReferenceParserTests.cs +++ b/test/dotnet.Tests/CommandTests/Reference/Add/AddReferenceParserTests.cs @@ -38,15 +38,6 @@ public void AddReferenceHasInteractiveFlag() .Should().BeTrue(); } - [Fact] - public void AddReferenceDoesHaveInteractiveFlagByDefault() - { - var result = Parser.Instance.Parse("dotnet add reference my.csproj"); - - result.GetValue(ReferenceAddCommandParser.InteractiveOption) - .Should().BeTrue(); - } - [Fact] public void AddReferenceWithoutArgumentResultsInAnError() { diff --git a/test/dotnet.Tests/CommandTests/Reference/Add/GivenDotnetAddReference.cs b/test/dotnet.Tests/CommandTests/Reference/Add/GivenDotnetAddReference.cs index ca40c346bcf4..d9e6a860925f 100644 --- a/test/dotnet.Tests/CommandTests/Reference/Add/GivenDotnetAddReference.cs +++ b/test/dotnet.Tests/CommandTests/Reference/Add/GivenDotnetAddReference.cs @@ -19,7 +19,7 @@ dotnet reference add ... [options] Options: -f, --framework Add the reference only when targeting a specific framework. --interactive Allows the command to stop and wait for user input or action (for example to complete - authentication). [default: True] + authentication). [default: False] --project The project file to operate on. If a file is not specified, the command will search the current directory for one. -?, -h, --help Show command line help."; From 39c3d8bb06277df7ba5180ab4fcb653dcdbcb00e Mon Sep 17 00:00:00 2001 From: Chet Husk Date: Thu, 10 Apr 2025 15:56:26 -0500 Subject: [PATCH 3/3] fix a few more expectations --- .../CommandLineOptionsTests.cs | 2 +- .../MSBuild/GivenDotnetPublishInvocation.cs | 26 +++++++++++++------ .../MSBuild/GivenDotnetRestoreInvocation.cs | 3 ++- .../MSBuild/GivenDotnetRunInvocation.cs | 3 ++- .../Run/GivenDotnetRunBuildsCsProj.cs | 17 ------------ 5 files changed, 23 insertions(+), 28 deletions(-) diff --git a/test/dotnet-watch.Tests/CommandLineOptionsTests.cs b/test/dotnet-watch.Tests/CommandLineOptionsTests.cs index 996dd27370ca..30d70643855a 100644 --- a/test/dotnet-watch.Tests/CommandLineOptionsTests.cs +++ b/test/dotnet-watch.Tests/CommandLineOptionsTests.cs @@ -424,7 +424,7 @@ public void ShortFormForLaunchProfileArgumentWorks() [InlineData(new[] { "--framework", "net9.0" }, new[] { "-property:TargetFramework=net9.0", NugetInteractiveProperty })] [InlineData(new[] { "--runtime", "arm64" }, new[] { "-property:RuntimeIdentifier=arm64", "-property:_CommandLineDefinedRuntimeIdentifier=true", NugetInteractiveProperty })] [InlineData(new[] { "--property", "b=1" }, new[] { "--property:b=1", NugetInteractiveProperty })] - [InlineData(new[] { "--interactive" }, new[] { NugetInteractiveProperty })] + [InlineData(new[] { "--interactive" }, new[] { "-property:NuGetInteractive=true" })] [InlineData(new[] { "--no-restore" }, new[] { NugetInteractiveProperty, "-restore:false" })] [InlineData(new[] { "--sc" }, new[] { NugetInteractiveProperty, "-property:SelfContained=True", "-property:_CommandLineDefinedSelfContained=true" })] [InlineData(new[] { "--self-contained" }, new[] { NugetInteractiveProperty, "-property:SelfContained=True", "-property:_CommandLineDefinedSelfContained=true" })] diff --git a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetPublishInvocation.cs b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetPublishInvocation.cs index 9828fce33fd1..410b3286914f 100644 --- a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetPublishInvocation.cs +++ b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetPublishInvocation.cs @@ -19,6 +19,7 @@ public GivenDotnetPublishInvocation(ITestOutputHelper output) private static readonly string[] ExpectedPrefix = ["-maxcpucount", "-verbosity:m", "-tlp:default=auto", "-nologo"]; private static readonly string[] ExpectedProperties = ["--property:_IsPublishing=true"]; + private static readonly string NuGetDisabledProperty = "-property:NuGetInteractive=false"; [Theory] [InlineData(new string[] { }, new string[] { })] @@ -56,7 +57,7 @@ public void MsbuildInvocationIsCorrect(string[] args, string[] expectedAdditiona command.GetArgumentTokensToMSBuild() .Should() - .BeEquivalentTo([.. ExpectedPrefix, "-restore", "-target:Publish", .. ExpectedProperties, .. expectedAdditionalArgs]); + .BeEquivalentTo([.. ExpectedPrefix, "-restore", "-target:Publish", .. ExpectedProperties, .. expectedAdditionalArgs, NuGetDisabledProperty]); }); } @@ -68,14 +69,23 @@ public void MsbuildInvocationIsCorrectForSeparateRestore(string[] args, string[] var msbuildPath = ""; var command = PublishCommand.FromArgs(args, msbuildPath); - command.SeparateRestoreCommand - .GetArgumentTokensToMSBuild() + var restoreTokens = + command.SeparateRestoreCommand + .GetArgumentTokensToMSBuild(); + output.WriteLine("restore tokens:"); + output.WriteLine(string.Join(" ", restoreTokens)); + restoreTokens .Should() - .BeEquivalentTo([.. ExpectedPrefix, "-target:Restore", "-tlp:verbosity=quiet", .. ExpectedProperties]); + .BeEquivalentTo([.. ExpectedPrefix, "-target:Restore", "-tlp:verbosity=quiet", .. ExpectedProperties, NuGetDisabledProperty]); - command.GetArgumentTokensToMSBuild() + var buildTokens = + command.GetArgumentTokensToMSBuild(); + output.WriteLine("build tokens:"); + output.WriteLine(string.Join(" ", buildTokens)); + + buildTokens .Should() - .BeEquivalentTo([.. ExpectedPrefix, "-nologo", "-target:Publish", .. ExpectedProperties, .. expectedAdditionalArgs]); + .BeEquivalentTo([.. ExpectedPrefix, "-nologo", "-target:Publish", .. ExpectedProperties, .. expectedAdditionalArgs, NuGetDisabledProperty]); } [Fact] @@ -90,7 +100,7 @@ public void MsbuildInvocationIsCorrectForNoBuild() command.GetArgumentTokensToMSBuild() .Should() - .BeEquivalentTo([.. ExpectedPrefix, "-target:Publish", .. ExpectedProperties, "-property:NoBuild=true"]); + .BeEquivalentTo([.. ExpectedPrefix, "-target:Publish", .. ExpectedProperties, "-property:NoBuild=true", NuGetDisabledProperty]); } [Fact] @@ -101,7 +111,7 @@ public void CommandAcceptsMultipleCustomProperties() command.GetArgumentTokensToMSBuild() .Should() - .BeEquivalentTo([.. ExpectedPrefix, "-restore", "-target:Publish", .. ExpectedProperties, "--property:Prop1=prop1", "--property:Prop2=prop2"]); + .BeEquivalentTo([.. ExpectedPrefix, "-restore", "-target:Publish", .. ExpectedProperties, "--property:Prop1=prop1", "--property:Prop2=prop2", NuGetDisabledProperty]); } } } diff --git a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRestoreInvocation.cs b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRestoreInvocation.cs index e5c4a91adeb8..c109c4ac9b91 100644 --- a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRestoreInvocation.cs +++ b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRestoreInvocation.cs @@ -9,6 +9,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests public class GivenDotnetRestoreInvocation : IClassFixture { private static readonly string[] ExpectedPrefix = ["-maxcpucount", "-verbosity:m", "-tlp:default=auto", "-nologo", "-target:Restore"]; + private static readonly string NuGetDisabledProperty = "-property:NuGetInteractive=false"; private static readonly string WorkingDirectory = TestPathUtilities.FormatAbsolutePath(nameof(GivenDotnetRestoreInvocation)); @@ -49,7 +50,7 @@ public void MsbuildInvocationIsCorrect(string[] args, string[] expectedAdditiona RestoreCommand.FromArgs(args, msbuildPath) .GetArgumentTokensToMSBuild() .Should() - .BeEquivalentTo([.. ExpectedPrefix, .. expectedAdditionalArgs]); + .BeEquivalentTo([.. ExpectedPrefix, .. expectedAdditionalArgs, NuGetDisabledProperty]); }); } } diff --git a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRunInvocation.cs b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRunInvocation.cs index 6b291ec53c76..a98dbd8572f0 100644 --- a/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRunInvocation.cs +++ b/test/dotnet.Tests/CommandTests/MSBuild/GivenDotnetRunInvocation.cs @@ -9,6 +9,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests public class GivenDotnetRunInvocation : IClassFixture { private static readonly string[] ConstantRestoreArgs = ["-nologo", "-verbosity:quiet"]; + private static readonly string NuGetDisabledProperty = "-property:NuGetInteractive=false"; public ITestOutputHelper Log { get; } @@ -41,7 +42,7 @@ public void MsbuildInvocationIsCorrect(string[] args, string[] expectedArgs) var command = RunCommand.FromArgs(args); command.RestoreArgs .Should() - .BeEquivalentTo([.. ConstantRestoreArgs, .. expectedArgs]); + .BeEquivalentTo([.. ConstantRestoreArgs, .. expectedArgs, NuGetDisabledProperty]); }); } finally diff --git a/test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsCsProj.cs b/test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsCsProj.cs index 9dcfbdc83efe..052377b1a83b 100644 --- a/test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsCsProj.cs +++ b/test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsCsProj.cs @@ -697,23 +697,6 @@ public void ItRunsWithTheSpecifiedVerbosity() } } - [Fact] - public void ItDoesShowImportantLevelMessageByDefault() - { - var testAppName = "MSBuildTestApp"; - var testInstance = _testAssetsManager.CopyTestAsset(testAppName) - .WithSource() - .WithProjectChanges(ProjectModification.AddDisplayMessageBeforeRestoreToProject); - - var result = new DotnetCommand(Log, "run") - .WithWorkingDirectory(testInstance.Path) - .Execute(); - - // this message should show because interactivity (and therefore nuget auth) is the default - result.Should().Pass() - .And.HaveStdOutContaining("Important text"); - } - [Fact] public void ItDoesNotShowImportantLevelMessageByDefaultWhenInteractivityDisabled() {