Visual Studio Code Code Formatting

  
  1. Visual Studio Code Code Formatting Settings
  2. Visual Studio Code Code Formatting Online

Format the class file and arrange fields, properties and methods as per StyleCop rules.

Features

  • Format the class file (.cs) to arrange members of class in the proper order.
  • Using statements are brought inside namespace block.
  • Unwanted namespaces are removed.
  • Unwanted space are removed.
  • Proper space introduced where ever required.
  • Adds header comments on members of the class.
  • Modifies the comment on the members if signature of the member is changed
  • Can group members by regions

How do you auto format code in Visual Studio? How do I fix the Visual Studio compile error, “mismatch between processor architecture”? Can you force Visual Studio to always run as an Administrator in Windows 8? What are the differences between Visual Studio Code and Visual Studio? Code Style: PHP Tools. The default code style is compliant with the formatting in PHP Tools for Visual Studio. This style focuses on leaving the code visual structure as untouched as possible, while normalizing the whitespaces where possible. Visual Studio Code is a code editor redefined and optimized for building and debugging modern web and cloud applications. Visual Studio Code is free and available on your favorite platform.

Feature Format class

Members of the class are arranged in following order

  • Constants
  • Fields
  • Constructors
  • Properties
  • Methods

Furthermore the members are also sorted by access modifiers as follows

  • public
  • internal
  • protected
  • private

How to use

After installation can execute format code command from two different place.

Option 1

  1. Go to any .cs file and open in code editor.
  2. Right click on the code file and you will get option to 'Format Code' as shown below.
  3. You can also invoke this command using Keyboard shortcut 'Ctrl+D, Ctrl+F'

Option 2

  1. Go to solution explorer
  2. Select the .cs file which needs to be formatted
  3. Right click on the file and you will get 'Format Code' option on the menu as shown below.

Option 3

  1. Go to solution explorer
  2. Select the any project which needs to be formatted
  3. Right click on that project and you will get 'Code Formatter > Format Code' option on the menu as shown below.
Visual studio code formatting shortcut

Option 4

  1. Go to solution explorer
  2. Select the solution node
  3. Right click on that solution node and you will get 'Code Formatter > Format Code' option on the menu as shown below.
Visual

In Option 3 and 4, all the .cs file present within the Project or solution respectively will get formatted automatically.

Settings

Settings for tool can be accessed from Visual Studio options screen as shown below.

General Settings

Type Layout

You can customize the layout of the class or interface by setting required layout under Type layout setting

Note: That the first time when this extension is installed, type layout will be blank. Hence first time user will have to configure the type layout, and you can also set type layout with the help of the default templates.

Visual

File Header

You can also choose to include class header by updating setting under File Header.

You can customize the file header format and you can use the available replacement to format the header.

You can also have the different file header template based on the solution or project also.

Visual Studio Code Code Formatting Settings

To have customized file header for a perticular solution, go to Solution and right click and go to 'Code Formatter >> Add Header Setting File'. And you can set perticular format in that setting file.

Same is applicable of project level file header as well.

Note: File template selection will first check for project header setting file, if not found then it will look for solution header setting file and if the file is not present then global header will be applied.

Download this extension from the VS Gallery

Installation Guide:

1. If you are installing it manually using VSIX file then make sure you uninstall the previous version anf then install the new version. Because if at the same time multiple version are installed of the same extension then extension will be disabled by Visual Studio.

2. It is advisable to install the extension from Tools > Extensions and Update option.

Visual Studio Code Code Formatting Online

License