C# – How to force indentation of C# conditional directives

cvisual studio

is there an option how to disable that #if, #endif and other directives are not indended after Edit -> Advanced -> Format document in Visual Studio?

Thank you!

Best Answer

Look at StyleCop.

StyleCop analyzes C# source code to enforce a set of style and consistency rules. It can be run from inside of Visual Studio or integrated into an MSBuild project. StyleCop has also been integrated into many third-party development tools.

You can even add custom rules: Creating Custom Rules for Microsoft Source Analyzer

Hope it helps.