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 incorrectly removing using directives of Blazor/Razor components since 8.0.2 #72160

Open
jonashendrickx opened this issue Feb 17, 2024 · 3 comments
Assignees
Milestone

Comments

@jonashendrickx
Copy link

jonashendrickx commented Feb 17, 2024

Version Used:

.NET 8.0.201

Steps to Reproduce:

  • Upgrade from .NET 8.0.1 (feature v101) to .NET 8.0.2
  • Run dotnet format

I've also attempted to remove lines from _imports.razor, but that didn't seem to make a difference.

Diagnostic Id:

If this is a report about a bug in an analyzer, please include the diagnostic if possible (e.g. "IDE0030").

Expected Behavior:

It should not happen.

Actual Behavior:

When running dotnet format, it seems to remove all the usings everywhere in my unit tests where I do not have a GlobalUsings.cs file.

My _Imports.razor:

...
@using Passwordless.AdminConsole.Components
@using Passwordless.AdminConsole.Components.Shared
@using Passwordless.AdminConsole.Components.Shared.ApexCharts
@using Passwordless.AdminConsole.Components.Shared.Cards
@using Passwordless.AdminConsole.Components.Shared.Icons
@using Passwordless.AdminConsole.Components.Shared.Links
@using Passwordless.AdminConsole.Components.Shared.Stats
...

It would remove the using clauses in my unit test project of the lines above. Is this expected behavior? It was not happening in .NET 8.0.1 or .NET 8.0.0.

In Program.cs I am also seeing the using import removed for the following line:

app.MapRazorComponents<App>();

If I add a GlobalUsings declaration in my unit tests project, it no longer seems to happen.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 17, 2024
@jonashendrickx
Copy link
Author

jonashendrickx commented Feb 17, 2024

Even the default Blazor templates are broken when adding the .editorconfig from dotnet/roslyn or dotnet/aspnetcore.

Folder structure:
--Program.cs
--Components/App.razor

The documentation does not seem to suggest that both files have to be in the same folder.

@JoeRobich
Copy link
Member

Cross-posted from dotnet/format#2119

When I build locally I see the following error:

Source/passwordless-server/src/AdminConsole/Program.cs(212,28): error CS0246: The type or namespace name 'App' could not be found (are you missing a using directive or an assembly reference?)

I think it is related to #72015. Roslyn wasn't cleanly loading Blazor projects which would lead to some using directives appearing to be unused. This should be fixed in the next released SDKs.

@jonashendrickx
Copy link
Author

@JoeRobich Thank you for pointing me in the right direction! Very much appreciated!

@jonashendrickx jonashendrickx changed the title dotnet format incorrectly removing using directives of Blazor/Razor components since 8.0.201 dotnet format incorrectly removing using directives of Blazor/Razor components since 8.0.2 Feb 19, 2024
@arunchndr arunchndr added Bug and removed untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 11, 2024
@arunchndr arunchndr added this to the 17.12 milestone Jun 11, 2024
@CyrusNajmabadi CyrusNajmabadi modified the milestones: 17.12, 17.13 Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants