Skip to content
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

[dotnet format] 'Using directive is unnecessary' false positive in combination with Roslyn source generator #40427

Open
BinaryTENSHi opened this issue Apr 25, 2024 · 2 comments
Labels
Area-Format untriaged Request triage from a team member

Comments

@BinaryTENSHi
Copy link

BinaryTENSHi commented Apr 25, 2024

Describe the bug

Running dotnet format --verify-no-changes reports a error IDE0005: Using directive is unnecessary. false positive when the namespace is from a used class that was generated using a Roslyn source generator.

Running dotnet format removes the using {namespace}; which then leads to a compilation error afterward.

To Reproduce

I have created a minimal reproducible example here: https://github.com/BinaryTENSHi/dotnet-format-source-generator

  1. Clone the repository
  2. Run dotnet format --verify-no-changes

Running dotnet format and then dotnet build results in a compilation error.

Further technical details

.NET SDK 8.0.204

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-NetSDK untriaged Request triage from a team member labels Apr 25, 2024
@Basyras
Copy link

Basyras commented May 1, 2024

Just start having the same problem... I would also note that the somewhat required dotnet build before dotnet format (to make sure all source generated file are present) doesn't help. I was already using net8 for some time but just recently updated to 8.0.204 SDK so the breaking must happened somewhere between those versions. Can repro locally and on our build machine via azure pipelines too (where same SDK version is installed.)

System Info:

Visual studio: 17.9.6
dotnet sdk: 8.0.204
dotnet runtime: 8.0.4

@suhrjo
Copy link

suhrjo commented Jun 12, 2024

Having the same issue where dotnet format style removes used imports. When running dotnet format style -v detailed I get the output:

error IDE0005: Using directive is unnecessary

Which then removes the import. When running dotnet build after, I receive following output:

error CS0246: The type or namespace name 'X' could not be found (are you missing a using directive or an assembly reference?)

System Info:

dotnet runtime version: 8.0.6
dotnet CLI/SDK version: 8.0.301
running dotnet format with Windows Terminal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Format untriaged Request triage from a team member
Projects
None yet
Development

No branches or pull requests

4 participants