You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Visual Studio for Mac, you can add an [EditorConfig](http://editorconfig.org/) file to your project or codebase to enforce consistent coding styles for everyone that works in the codebase. The settings declared in the EditorConfig file take precedence over global Visual Studio text editor settings. Using EditorConfig within your project or codebase allows you to set your coding style, preferences, and warnings for your project. This makes it easier for all Visual Studio for Mac users to adhere to the coding practices of a project.
14
+
In Visual Studio for Mac, you can add an [EditorConfig](http://editorconfig.org/) file to your project or solution to enforce consistent coding styles for everyone that works in the codebase. The settings declared in the EditorConfig file take precedence over global Visual Studio for Mac text editor settings. Using an EditorConfig file within your project or codebase allows you to set your coding style, preferences, and warnings for your project. Because the file is part of your codebase, it makes it easier for all users to adhere to the coding practices of a project, regardless of the IDE or code editor that they use.
15
15
16
16
[EditorConfig](http://editorconfig.org/) files are supported on many IDEs and code editors, including Visual Studio 2017.
17
17
18
18
## Supported settings
19
19
20
-
The editor in Visual Studio supports the core set of [EditorConfig properties](http://editorconfig.org/#supported-properties):
20
+
The editor in Visual Studio for Mac supports the core set of [EditorConfig properties](http://editorconfig.org/#supported-properties):
21
21
22
22
-`indent_style`
23
23
-`indent_size`
@@ -28,20 +28,26 @@ The editor in Visual Studio supports the core set of [EditorConfig properties](h
28
28
-`insert_final_newline`
29
29
-`root`
30
30
31
-
EditorConfig also supports [Code style formatting](https://docs.microsoft.com/visualstudio/ide/editorconfig-code-style-settings-reference) in C#.
31
+
EditorConfig also supports [Coding conventions](https://docs.microsoft.com/visualstudio/ide/editorconfig-code-style-settings-reference) in C#.
32
32
33
33
## Add an EditorConfig file to a project
34
34
35
35
### Adding a new EditorConfig file
36
36
37
-
1. Open your project in Visual Studio for Mac. Select the project node that you wish to add files to.
37
+
1. Open your project in Visual Studio for Mac. Select either the solution or project node that you wish to add the EditorConfig file to. Adding the file to the solution directory applies the .editorconfig settings to all projects in the solution.
38
38
39
-
2. With the project node selected, go to **File > New File…** in the menu bar to open the **New File** dialog.
39
+
2. Right-click on the node and select **Add > New File…** to open the **New File** dialog:
40
+
41
+

40
42
41
43
3. Choose **Misc > Empty Text File** and give it the **Name**`.editorconfig`. Press **New** to create the file and open it in the editor:
42
44
43
45

44
46
47
+
Adding the item at the solution level automatically creates and nests it in a **Solution Items** folder:
48
+
49
+

50
+
45
51
4. Edit the file. For example:
46
52
47
53
```EditorConfig
@@ -59,29 +65,41 @@ EditorConfig also supports [Code style formatting](https://docs.microsoft.com/vi
59
65
csharp_new_line_before_open_brace = none
60
66
```
61
67
62
-
4. Adding the file does not automatically update your settings. To reflect the settings from the `.editorconfig` file, select the project node and choose **Edit > Format > Format Document** from the menu bar:
68
+
4. While adding the automatically update your settings for any new code that you add, existing code will need to be reformatted. To reflect the settings from the `.editorconfig` file, select the project node and choose **Edit > Format > Format Document** from the menu bar:
63
69
64
70

65
71
66
72
### Adding an existing EditorConfig file
67
73
68
74
If you're working with a project or solution that already contains an `.editorconfig` file, there is nothing that you need to do to apply the settings. Any new lines of code are formatted according to the EditorConfig settings. You should note that while Visual Studio for Mac will respect `.editorconfig` files at the solution level, they might not appear in the solution pad due to the fact the files beginning with `.` are hidden files in macOS.
69
75
70
-
You may want to reuse an existing `.editorconfig` file in your project. To add an existing file, you first need to display hidden files in Finder by entering the following command in **Terminal**:
76
+
You may want to reuse an existing `.editorconfig` file in your project. To add an existing file, do the following:
1. Right-click on the folder you wish to add it to and select **Add > Add Files…**.
79
+
80
+
2. Browse to the directory of the required file.
81
+
82
+
3. Files beginning with `.` (such as `.editorconfig`) are hidden files in macOS, so press **Command + Shift + .** to make the `.editorconfig` file visible.
76
83
77
-
Once the `.editorconfig` file is visible, drag it to your project node. When you're presented with the following dialog, select the **Copy the file to the directory** option and select**OK**:
84
+
4. Select the `.editorconfig` file and click **Open**:
78
85
79
-

86
+

80
87
81
-
To reflect the settings from the `.editorconfig` file, select the project node and choose **Edit > Format > Format Document** from the menu bar.
88
+
5. When you're presented with the following dialog, select the **Copy the file to the directory** option and select **OK**:
89
+
90
+

91
+
92
+
### Reflecting .editorconfig settings
93
+
94
+
Once you add an EditorConfig file to your codebase, any new code added is automatically formatted according to the specified settings. Existing code doesn't automatically reflect the settings unless you format the codebase.
95
+
96
+
To reflect the settings from the `.editorconfig` file, select the solution node and choose **Edit > Format > Format Document** from the menu bar:
97
+
98
+

82
99
83
100
## Editing an EditorConfig file
84
101
102
+
85
103
EditorConfig files use a straightforward file layout to specify settings, which is explained below using a previous example:
0 commit comments