dotnet / format

Home for the dotnet-format command
MIT License
1.94k stars 172 forks source link

using --diagnostics appears to be broken (.net 6.0.301) #1645

Open WillClayworth opened 2 years ago

WillClayworth commented 2 years ago

Running the following dotnet format command reports an error in latest .Net version (6.0.301)

dotnet format --diagnostics 'IDE0001'

Unhandled exception: System.IO.FileNotFoundException: The file 'IDE0001' does not appear to be a valid project or solution file. at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceFinder.FindFile(String workspacePath) at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceFinder.FindWorkspace(String searchDirectory, String workspacePath) at Microsoft.CodeAnalysis.Tools.FormatCommandCommon.ParseWorkspaceOptions(ParseResult parseResult, FormatOptions formatOptions) at Microsoft.CodeAnalysis.Tools.Commands.RootFormatCommand.FormatCommandDefaultHandler.InvokeAsync(InvocationContext context) at System.CommandLine.Invocation.InvocationPipeline.<>cDisplayClass4_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass23_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass16_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass27_0.<b1>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass25_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<b24_0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass22_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass11_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<b10_0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<b__0>d.MoveNext()

JoeRobich commented 2 years ago

This should be resolved in 6.0.4xx SDK branch.

~@WillClayworth you can use --diagnostics=IDE0001 as a workaround with other versions.~ - Edit: This worked for the --include options but not for --diagnostics. =(

pseidel-kcf commented 2 years ago

FWIW I still get errors even with the work around

$ dotnet --version 6.0.301 $ dotnet format --version 6.3.322007+dc5c84e776364e1c23a5cf2d1a848d4022f8634f $ $ dotnet format --diagnostics=IDE0001 Unhandled exception: System.IO.FileNotFoundException: The file 'IDE0001' does not appear to be a valid project or solution file. at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceFinder.FindFile(String workspacePath) at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceFinder.FindWorkspace(String searchDirectory, String workspacePath) at Microsoft.CodeAnalysis.Tools.FormatCommandCommon.ParseWorkspaceOptions(ParseResult parseResult, FormatOptions formatOptions) at Microsoft.CodeAnalysis.Tools.Commands.RootFormatCommand.FormatCommandDefaultHandler.InvokeAsync(InvocationContext context) at System.CommandLine.Invocation.InvocationPipeline.<>cDisplayClass4_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass23_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass16_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass27_0.<b1>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass25_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<b24_0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass22_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>cDisplayClass11_0.<b0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<b10_0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<b__0>d.MoveNext()

nathansolidatus commented 2 years ago

same error with --diagnostics=IDE0001

JoeRobich commented 2 years ago

@pseidel-kcf @nathansolidatus Sorry about that. My next suggestion would be to install our 6.x build as a global tool and invoke the global tool rather than using the dotnet CLI.

dotnet tool install -g dotnet-format --version "6.*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json

Be sure to invoke as dotnet-format instead of dotnet format. The hyphen is important.

mukunku commented 2 years ago

I'm also experiencing this issue and would prefer to use the .net 6 version. Are there plans to address this issue or at least discontinue the use of that argument if it won't be supported?

mausch commented 1 year ago

My next suggestion would be to install our 6.x build as a global tool and invoke the global tool rather than using the dotnet CLI.

This doesn't seem to be working either. I don't get an error but the cmdline argument just seems to get ignored. When I run dotnet-format --diagnostics IDE0001 it does the same as dotnet-format

Also dotnet-format doesn't seem to be working at all if not installed globally (installing things globally is bad for well-known reasons).

$ dotnet dotnet-format
Could not execute because the specified command or file was not found.
Possible reasons for this include:
  * You misspelled a built-in dotnet command.
  * You intended to execute a .NET program, but dotnet-dotnet-format does not exist.
  * You intended to run a global tool, but a dotnet-prefixed executable with this name could not be found on the PATH.

$ dotnet tool install dotnet-format --version "6.*" --add-source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json
You can invoke the tool from this directory using the following commands: 'dotnet tool run dotnet-format' or 'dotnet dotnet-format'.
Tool 'dotnet-format' (version '6.4.352107') was successfully installed. Entry is added to the manifest file /home/mauricio/prg/SolrNet/dotnet-tools.json.

$ dotnet dotnet-format --version
6.4.352107+29f0a64560676efb3c24bc01942bcd84d807b335

$ dotnet dotnet-format --diagnostics IDE0001
Unhandled exception: System.IO.FileNotFoundException: The file 'IDE0001' does not appear to be a valid project or solution file.
   at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceFinder.FindFile(String workspacePath) in /_/src/Workspaces/MSBuildWorkspaceFinder.cs:line 70
   at Microsoft.CodeAnalysis.Tools.Workspaces.MSBuildWorkspaceFinder.FindWorkspace(String searchDirectory, String workspacePath) in /_/src/Workspaces/MSBuildWorkspaceFinder.cs:line 34
   at Microsoft.CodeAnalysis.Tools.FormatCommandCommon.ParseWorkspaceOptions(ParseResult parseResult, FormatOptions formatOptions) in /_/src/Commands/FormatCommandCommon.cs:line 303
   at Microsoft.CodeAnalysis.Tools.Commands.RootFormatCommand.FormatCommandDefaultHandler.InvokeAsync(InvocationContext context) in /_/src/Commands/RootFormatCommand.cs:line 43
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass21_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass18_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__17_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__4_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass7_0.<<UseExceptionHandler>b__0>d.MoveNext()
wzchua commented 1 year ago

The workaround is dotnet format —diagnostics=IDE0005

wzchua commented 1 year ago

I have verified it is working correctly with the .NET7 SDK with the space

mausch commented 1 year ago

I can confirm the issue has been fixed in .NET 7, thanks.

Hopefully the fix can be backported to .NET 6, especially considering it's LTS?