format icon indicating copy to clipboard operation
format copied to clipboard

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

Open WillClayworth opened this issue 3 years ago • 9 comments

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.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseParseErrorReporting>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass27_0.<<UseVersionOption>b__1>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseTypoCorrections>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__24_0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseParseDirective>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseDebugDirective>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()

WillClayworth avatar Jun 17 '22 13:06 WillClayworth

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. =(

JoeRobich avatar Jun 20 '22 20:06 JoeRobich

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.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseParseErrorReporting>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass27_0.<<UseVersionOption>b__1>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseTypoCorrections>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__24_0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseParseDirective>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<<UseDebugDirective>b__0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext() --- End of stack trace from previous location --- at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()

pseidel-kcf avatar Jun 30 '22 17:06 pseidel-kcf

same error with --diagnostics=IDE0001

nathansolidatus avatar Jul 08 '22 13:07 nathansolidatus

@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.

JoeRobich avatar Jul 09 '22 17:07 JoeRobich

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?

mukunku avatar Aug 09 '22 19:08 mukunku

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()

mausch avatar Dec 04 '22 19:12 mausch

The workaround is dotnet format —diagnostics=IDE0005

wzchua avatar Dec 08 '22 10:12 wzchua

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

wzchua avatar Dec 10 '22 03:12 wzchua

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?

mausch avatar Dec 12 '22 08:12 mausch