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

.net 8.0.2 Blazor _imports.razor & using IDE0005 #2119

Open
jonashendrickx opened this issue Feb 16, 2024 · 4 comments
Open

.net 8.0.2 Blazor _imports.razor & using IDE0005 #2119

jonashendrickx opened this issue Feb 16, 2024 · 4 comments

Comments

@jonashendrickx
Copy link

jonashendrickx commented Feb 16, 2024

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.

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

It is an open-source project: https://github.com/bitwarden/passwordless-server

@JoeRobich
Copy link
Member

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 dotnet/roslyn#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.

@jjonescz
Copy link
Member

@JoeRobich I can repro this with dotnet format from SDK 8.0.200, but I don't think it's the same issue as dotnet/roslyn#72015 (that one didn't ship in SDK 8.0.200). I also don't see any build errors when building from commandline using SDK 8.0.200 (I think you must be using VS 17.10 or something like that if you are seeing those errors). And nothing bad in the binlog of dotnet format either (the csc commandline is nearly identical to the one from dotnet build's binlog which works). So not sure what is going on.

@jonashendrickx
Copy link
Author

@jjonescz If you start a new Blazor Web project, and then put one of the editorconfig's you have in your repositories, and run dotnet format, it will fail to resolve the App component too. just make sure you have dotnet_diagnostic.IDE0005.severity = none set to anything but silent.

Using dotnet format is removing using directives. I don't know how many .NET developers use .editorconfig or dotnet format, but something has been broken with the release of .NET 8 and MSBuild 17.9, which might have gotten worse with 17.10-preview1. It all seems related. If you set the above rule to silent, no refactoring happens with dotnet format and all is fine. But on 17.8 and earlier, we were never having any issues.

Is there a possibility for me to test 72057 on my machine with our project?

@jjonescz
Copy link
Member

I completely agree with you - there appears to be a bug in dotnet format in 8.0.200 which makes it not work with the razor source generator.

Is there a possibility for me to test 72057 on my machine with our project?

You could install Microsoft.Net.Compilers.Toolset NuGet package to force a specific version of roslyn. I just tried that in your repo and it didn't fix the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants