Click here to Skip to main content
15,847,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)

I can almost hear the clamour of criticism from here, but I'm working alone and I have always found compiler directives much easier to read when they are placed at the same indent level as the code they are affecting. In older versions of Visual Studio, it left them where I put them, but 2015 insists on moving them whenever the file is formatted.

Does anyone know of a plugin or setting that will let me keep them where I like them?

Kind wishes ~ Patrick

PS - Please note, if I were working in a team, I would of course follow whatever convention the team had decided upon.

What I have tried:

I've turned off Options | C# | Formatting | General | Automatically format statement on ; } and paste
Updated 23-Feb-16 7:05am
Philippe Mori 23-Feb-16 19:26pm    
Compiler directive should always be at left margin except for some case like #region.

However, in Visual Studio 2015, that kind of stuff is someone broken. In particular, Visual Studio 2015 will sometime mess code after pasting something like #if something. New editor based on Roslyn seems to ignore the fact that human write code from left to right and sometime insert code into existing code.

Report the problem to Microsoft using the tool in the upper right corner.

Although there are some options, from what I've heard they are also broken in some case. Thus, presently all options seems to not always work properly.

In some case, you can prevent Visual Studio to mess up code by writing code "backward" or using some other tricks while editing. If one notice the problem immediatly, he might undo its change. However, when affected code is outside of visible code, one have to fix code manually.

Part of the problem is that the new editor make some change to early. For example, it will reformat code as soon as one write # no even yet knowing if it will be #if, #region or something else.
Patrick Skelton 24-Feb-16 5:19am    
In these days of colour-coding editors that take account of which compiler directives are active, I don't actually see the need to stick to the ancient notion that compiler directives should always go against the left margin, but that's a subject for another thread.

Thank you very much for the information.

Kind wishes ~ Patrick

1 solution

There is nothing built into Visual Studio that will turn that off and the edit document formatter does not apply indenting to directives. I don't know of a plugin that puts the indenting in or maintains it.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900