dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.7k stars 1.06k forks source link

`-interactive` switch is accepted, although only `--interactive` works #29564

Open danmoseley opened 1 year ago

danmoseley commented 1 year ago

Prompted by the very helpful Nuget error message

The plugin credential provider could not acquire credentials. Authentication may require manual action. Consider re-running the command with --interactive for `dotnet`, /p:NuGetInteractive="true" for MSBuild or removing the -NonInteractive switch for `NuGet`

Steps:

Result:

Expected:

Commentary:

Note that -interactive (one hyphen) does not give any error, it seems just ignored, whereas passing a made up switch does error:

PS C:\proj\1> dotnet restore -interactive -v:m
  Determining projects to restore...
  All projects are up-to-date for restore.

PS C:\proj\1> dotnet restore -interactiveFOOBAR -v:q
MSBUILD : error MSB1001: Unknown switch.
    Full command line: 'C:\Program Files\dotnet\sdk\7.0.101\MSBuild.dll -maxcpucount -verbosity:m -nologo -target:Restore -verbosity:q -interactiveFOOBAR -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:\Program Files\dotnet\sdk\7.0.101\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,C:\Program Files\dotnet\sdk\7.0.101\dotnet.dll'
  Switches appended by response files:
Switch: -interactiveFOOBAR

For switch syntax, type "MSBuild -help"

You can see by filtering the output of the build for 'interactive' and comparing one with two hyphens that only the two hyphens version works:

PS C:\proj\1> dotnet restore --interactive -v:d | findstr /sipc:"interactive"
       Command line arguments = "C:\Program Files\dotnet\sdk\7.0.101\MSBuild.dll -maxcpucount -verbosity:m -nologo -target:Restore -verbosity:d -property:NuGetInteractive=true -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:\Program Files\dotnet\sdk\7.0.101\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,C:\Program Files\dotnet\sdk\7.0.101\dotnet.dll"
       The "NuGetInteractive" property is a global property, and cannot be modified.
       The "NuGetInteractive" property is a global property, and cannot be modified.

PS C:\proj\1> dotnet restore -interactive -v:d | findstr /sipc:"interactive"
       Command line arguments = "C:\Program Files\dotnet\sdk\7.0.101\MSBuild.dll -maxcpucount -verbosity:m -nologo -target:Restore -verbosity:d -interactive -distributedlogger:Microsoft.DotNet.Tools.MSBuild.MSBuildLogger,C:\Program Files\dotnet\sdk\7.0.101\dotnet.dll*Microsoft.DotNet.Tools.MSBuild.MSBuildForwardingLogger,C:\Program Files\dotnet\sdk\7.0.101\dotnet.dll"

I'm not sure where this bug goes. I see that in some cases, NuGet itself handles --interactive eg here. But I think for the restore command, this may be taken care of within the dotnet/sdk repo.

version info:

PS C:\proj\1> dotnet --info
.NET SDK:
 Version:   7.0.101
 Commit:    bb24aafa11

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19044
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.101\

Host:
  Version:      7.0.1
  Architecture: x64
  Commit:       97203d38ba

.NET SDKs installed:
  3.1.426 [C:\Program Files\dotnet\sdk]
  6.0.307 [C:\Program Files\dotnet\sdk]
  7.0.100 [C:\Program Files\dotnet\sdk]
  7.0.101 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.31 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
dotnet-issue-labeler[bot] commented 1 year ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

baronfel commented 1 year ago

This is difficult because of how we integrate with MSBuild here. We pass along any CLI tokens that aren't explicitly recognized by the .NET CLI's restore command directly through to MSBuild. Since we don't fully model MSBuild's CLI surface area here, we do not know if a token is valid or not, so we have to assume that -interactive is something that might be useful to MSBuild. It's possible that we could try to look for one-off's of these kinds of token typos/mistakes, but it would IMO be a lot of manual work. If we had a fully-modeled CLI grammar then System.CommandLine would generate typo correction code automatically on our behalf.

As an aside, I've kind of been wanting to try modeling MSBuild's entire grammar with System.CommandLine...