Skip to content

--interactive should actually default to true in user-facing situations. #48353

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Cli/dotnet/CommonOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public static ForwardedOption<bool> 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<bool> InteractiveMsBuildForwardOption = InteractiveOption(acceptArgument: true).ForwardAsSingle(b => $"-property:NuGetInteractive={(b ? "true" : "false")}");
Expand Down
4 changes: 2 additions & 2 deletions test/dotnet-watch.Tests/CommandLineOptionsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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";

/// <summary>
/// Validates that options that the "run" command forwards to "build" command are forwarded by dotnet-watch.
Expand All @@ -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" })]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class GivenDotnetBuildInvocation : IClassFixture<NullCurrentSessionIdFixt
{
string[] ExpectedPrefix = ["-maxcpucount", "-verbosity:m", "-tlp:default=auto", "-nologo"];

const string NugetInteractiveProperty = "-property:NuGetInteractive=true";
const string NugetInteractiveProperty = "-property:NuGetInteractive=false";

private static readonly string WorkingDirectory =
TestPathUtilities.FormatAbsolutePath(nameof(GivenDotnetBuildInvocation));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
[Collection(TestConstants.UsesStaticTelemetryState)]
public class GivenDotnetCleanInvocation : IClassFixture<NullCurrentSessionIdFixture>
{
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];


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class GivenDotnetPackInvocation : IClassFixture<NullCurrentSessionIdFixtu
{
private static readonly string[] ExpectedPrefix = ["-maxcpucount", "-verbosity:m", "-tlp:default=auto", "-nologo", "-restore", "-target:pack"];
private static readonly string[] ExpectedNoBuildPrefix = ["-maxcpucount", "-verbosity:m", "-tlp:default=auto", "-nologo", "-target:pack"];
private readonly string[] ExpectedProperties = ["--property:_IsPacking=true", "-property:NuGetInteractive=true"];
private readonly string[] ExpectedProperties = ["--property:_IsPacking=true", "-property:NuGetInteractive=false"];

private static readonly string WorkingDirectory =
TestPathUtilities.FormatAbsolutePath(nameof(GivenDotnetPackInvocation));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ public GivenDotnetPublishInvocation(ITestOutputHelper output)
}

private static readonly string[] ExpectedPrefix = ["-maxcpucount", "-verbosity:m", "-tlp:default=auto", "-nologo"];
private static readonly string[] ExpectedProperties = ["--property:_IsPublishing=true", "-property:NuGetInteractive=true"];
private static readonly string[] ExpectedProperties = ["--property:_IsPublishing=true"];
private static readonly string NuGetDisabledProperty = "-property:NuGetInteractive=false";

[Theory]
[InlineData(new string[] { }, new string[] { })]
Expand Down Expand Up @@ -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]);
});
}

Expand All @@ -68,14 +69,23 @@ public void MsbuildInvocationIsCorrectForSeparateRestore(string[] args, string[]
var msbuildPath = "<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]
Expand All @@ -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]
Expand All @@ -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]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
[Collection(TestConstants.UsesStaticTelemetryState)]
public class GivenDotnetRestoreInvocation : IClassFixture<NullCurrentSessionIdFixture>
{
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 NuGetDisabledProperty = "-property:NuGetInteractive=false";
private static readonly string WorkingDirectory =
TestPathUtilities.FormatAbsolutePath(nameof(GivenDotnetRestoreInvocation));

Expand Down Expand Up @@ -49,7 +50,7 @@ public void MsbuildInvocationIsCorrect(string[] args, string[] expectedAdditiona
RestoreCommand.FromArgs(args, msbuildPath)
.GetArgumentTokensToMSBuild()
.Should()
.BeEquivalentTo([.. ExpectedPrefix, .. expectedAdditionalArgs]);
.BeEquivalentTo([.. ExpectedPrefix, .. expectedAdditionalArgs, NuGetDisabledProperty]);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
[Collection(TestConstants.UsesStaticTelemetryState)]
public class GivenDotnetRunInvocation : IClassFixture<NullCurrentSessionIdFixture>
{
private static readonly string[] ConstantRestoreArgs = ["-nologo", "-verbosity:minimal", "-property:NuGetInteractive=true"];
private static readonly string[] ConstantRestoreArgs = ["-nologo", "-verbosity:quiet"];
private static readonly string NuGetDisabledProperty = "-property:NuGetInteractive=false";

public ITestOutputHelper Log { get; }

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Microsoft.DotNet.Cli.MSBuild.Tests
[Collection(TestConstants.UsesStaticTelemetryState)]
public class GivenDotnetTestInvocation : IClassFixture<NullCurrentSessionIdFixture>
{
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ dotnet remove [<PROJECT>] package <PACKAGE_NAME>... [options]
<PACKAGE_NAME> 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<string, string> RemoveCommandHelpText = (defaultVal) => $@"Description:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool>(ReferenceAddCommandParser.InteractiveOption)
.Should().BeTrue();
}

[Fact]
public void AddReferenceWithoutArgumentResultsInAnError()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ dotnet reference add <PROJECT_PATH>... [options]
Options:
-f, --framework <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.";
Expand Down
17 changes: 0 additions & 17 deletions test/dotnet.Tests/CommandTests/Run/GivenDotnetRunBuildsCsProj.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
Expand Down
Loading