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

[Question] How to change format settings for C# code? #5036

Closed
ghost opened this issue Feb 4, 2022 · 3 comments
Closed

[Question] How to change format settings for C# code? #5036

ghost opened this issue Feb 4, 2022 · 3 comments
Labels

Comments

@ghost
Copy link

ghost commented Feb 4, 2022

I would like to know how can I change format settings for brackets, prefer "this" and other options that I can change on Visual Studio.

@nohwnd nohwnd added the Triaged label Feb 8, 2022
@JoeRobich
Copy link
Member

JoeRobich commented Feb 8, 2022

The C# extension supports configuring formatting options in an .editorconfig file. You can see details at https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/code-style-rule-options?view=vs-2022. Here is the configuration for newline before brace. You can run dotnet new editorconfig to generate a good starter .editorconfig. This approach also has support inside Visual Studio as well as with the dotnet-format command line tool.

@ssoher
Copy link

ssoher commented Feb 11, 2022

You can also put an omnisharp.json file under the same path with your solution file as well.

https://github.com/OmniSharp/omnisharp-roslyn/wiki/Configuration-Options

Alternatively you can use a single global omnisharp.json (I did not test this myself).

OmniSharp/omnisharp-roslyn#809

@ghost
Copy link
Author

ghost commented Feb 23, 2022

Thanks, I figured it out.

.editorconfig will always work. And we also can use generated Visual Studio .editorconfig.

@ghost ghost closed this as completed Feb 23, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants