Serge Intern
Serge Intern

Reputation: 2969

Why is '.editorconfig' not doing anything in Visual Studio 2017?

I have the following version of Visual Studio:

Microsoft Visual Studio Community 2017 Version 15.1 (26403.7) Release VisualStudio.15.Release/15.1.0+26403.7

I created a new project and added a .editorconfig file at my solution base folder.

Its content is the following:

root = true

[*.cs]
indent_style = space:warning
indent_size = 12:warning

# C# and Visual Basic code style settings:
[{*.cs,*.vb}]
dotnet_style_qualification_for_field = false:warning

The file location should be right:

.editorconfig <-- Here it is
ApplicationInsights.config
App_Data
App_Start
bin
Content
Controllers
favicon.ico
fonts
Global.asax
Global.asax.cs
Models
obj
packages.config
Properties
Scripts
Startup.cs
Views
Web.config
Web.config.backup.1
Web.Debug.config
Web.Release.config
WebApplication8.csproj
WebApplication8.csproj.user

But whenever I edit a .cs file, nothing special happen (despite indentation not following the rule), I expect a warning (after a build, for instance) to show up, but no.

Is there something wrong with my configuration, or is there something which could hinder the configuration from being applied?

Upvotes: 18

Views: 10381

Answers (5)

WARdd
WARdd

Reputation: 116

For me I was just missing .Net environment installation in Visual Studio.

To fix:

  • Open the vs_installer
  • Find relevant vs installation
  • Click modify
  • check .NET desktop development
  • Click modify

Upvotes: 0

thesupersoup
thesupersoup

Reputation: 81

I had this same problem. The solution was adding the .editorconfig file to the solution in my case. You can choose to either add it to the solution or the project, depending on whether you want it applied everywhere or just the individual project.

Solution Explorer → right-click your solution or project → AddExisting Item... (if you have the .editorconfig file in position at the root of the solution or project) or New Item... (then search for editorconfig in the Add New Item wizard and choose the appropriate type for your work).

Upvotes: 6

Andreas
Andreas

Reputation: 11

I solved a similar issue by placing the .editorconfig file at the root folder of the project, i.e., the same folder as your .sln file.

Upvotes: 1

yahiheb
yahiheb

Reputation: 147

I had a similar problem and this is how I solved it:

My solution folder had a parent folder named between square brackets [], like [ParentFolderName], so I removed the square brackets and everything worked as expected.

For a reason or another, the editorconfig file does not do anything when the solution folder has a parent folder named between square brackets. The IDE (in my case Visual Studio 2017) uses its settings.

Upvotes: 0

altumano
altumano

Reputation: 2735

  1. Try to put the .editorconfig file into the same folder as your source file. If it helps, try to move it up (into one of the parent directories) until you get it high enough to affect all the files you need.
  2. If you have any EditorConfig extensions installed, try to uninstall them. There were some related bugs reported.

Upvotes: 0

Related Questions