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

.razor files don't use C# formatting settings #10250

Closed
vsfeedback opened this issue Apr 11, 2024 · 5 comments
Closed

.razor files don't use C# formatting settings #10250

vsfeedback opened this issue Apr 11, 2024 · 5 comments
Assignees
Labels
author: migration bot 🤖 The issue was created by a issue mover bot. The author may not be the actual author feature-formatting

Comments

@vsfeedback
Copy link

This issue has been moved from a ticket on Developer Community.


[severity:It’s more difficult to complete my work]
Microsoft Visual Studio Community 2022 (64-bit) - Current
Version 17.9.6
No formatting extensions installed.

When I type a closing brace } in a C# .razor file, the opening brace { is moved to a new line.
These are my options:
Text editor > Code Cleanup > Run Code Cleanup profile on save: ☐
Text editor > C# > General > Automatic brace completion: ☐
Text editor > C# > Code Style > Formatting > General > all ☐
Text editor > C# > Code Style > Formatting > New lines > New line options for braces: all ☐

Example before:

	private void OnPriceClick() {
		OrderBy(x => x.Price);
	}
  

Action: remove closing brace and add it back in the same spot.

Example after:

	private void OnPriceClick()
	{
		OrderBy(x => x.Price);
	}
  

Edit: I realised that the C# code is inside a .razor file and not a .cs file. This matters a lot as razor files have their own settings. Formatting works fine in .cs files.
I can mitigate the issue by disabling Text editor > Razor (ASP.NET Core) > Advanced > Format On Type
This reduces the severity.


Original Comments

Feedback Bot on 4/11/2024, 01:12 AM:

(private comment, text removed)


Original Solutions

(no solutions)

@dotnet-policy-service dotnet-policy-service bot added untriaged author: migration bot 🤖 The issue was created by a issue mover bot. The author may not be the actual author labels Apr 11, 2024
@phil-allen-msft phil-allen-msft added this to the 17.11 Planning milestone Apr 18, 2024
@Armageddon0
Copy link

I seem to be having a similar problem. First commented on issue dotnet/roslyn#75881, but was directed to file an issue with the Razor project as my issue seems to only be happening in .razor files. Searching through the issues already reported I found this one that seems very similar.

Here are my current Visual Studio formatting settings
Text Editor -> General
Image
Text Editor -> Code Cleanup
Image
Text Editor -> C# -> General
Image
Text Editor -> C# -> Code Style -> Formatting
Image
Text Editor -> C# -> Code Style -> Formatting -> New Lines
Image
Text Editor -> Razor -> General
Image
Text Editor -> Razor -> Advanced
Image

Before updating to Visual Studio 17.12.0 everything appeared to be working as expected and my settings were being applied. Now however, it appears to be ignoring the new lines settings and thus when I run "Format Document" on a .razor file with Ctrl+K -> Ctrl+D it changes all braces to start on a new line.

Let me know if you need any further information.

@chenryIDSTC
Copy link

Same issue as @Armageddon0 here. On version 17.12.2.

@davidwengier
Copy link
Member

This was fixed by dotnet/roslyn#76066. Apologies, I missed updating this issue.

@davidwengier davidwengier self-assigned this Nov 29, 2024
@JarRami
Copy link

JarRami commented Jan 17, 2025

Still seeing the exact same behaviour as @Armageddon0 on version 17.12.4

@ryzngard
Copy link
Contributor

The fix is shipped in current 17.13 previews and will be in 17.13 GA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author: migration bot 🤖 The issue was created by a issue mover bot. The author may not be the actual author feature-formatting
Projects
None yet
Development

No branches or pull requests

7 participants