Browse the Visual Studio Code extension library, and make sure you've got the C# extension installed ms-dotnettools.csharp
Press Ctrl + , to open the Settings panel. Change the editor.formatOnType setting to be enabled. This wasn't enabled by default in my Visual Studio Code.
Restart Visual Studio Code. It should now make code auto-format when you complete the line with a semicolon, or when you close the outer brace of a scope.
Note: this is a global setting for the editor, so it may enable auto-formatting for other languages and not just C#.
This was tested on Visual Studio Code version 1.43.1.
Even after setting tab/space size in VSCode Omnisharp still uses its own rules you can change them by having an "omnisharp.json" with custom rules.
for more information on these rules and where you can add the file check this article.
Try to create an OmniSharp config for your project that will allow you to customize the formatting of C# code.
Create the omnisharp.json in the project root (near the .sln file)
I solved that issue by simply pressing F1, writing "format", and hitting enter.
In my case, there was no default formatter set in my environment so it prompted me options for formatters.
I believe there was only one for C#.
As you can see, the output is set to task. Change it to OmniSharp log and check if it says the dotnet version is not supported. If yes then update your dotnet version. Hope it helps.
I kept pressing Shift + Alt + F (Format Document), thinking my formatter is not working because it was not chaning something I though was misformatted:
namespace MyApp // Note: actual namespace depends on the project name.
{
internal class Program
{
public static async Task Main(string[] args)
{
Console.WriteLine("Hello World!");
var app = PublicClientApplicationBuilder
.Create(_clientId)
.WithAuthority(AzureCloudInstance.AzurePublic, _tenantId)
.WithRedirectUri("http://localhost")
.Build();
Console.WriteLine("Hello World!");
}
}
}
it turns out that with the default settings, the microsoft c# extension is ok with this formatting, it doesn't think there is something to fix. If I change the indentation of the first line it fixes it.