views:

187

answers:

2

Hello,

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!

+1  A: 

I'm afraid there's no direct setting in Visual Studio. If you find it, anyway, let me know :)
As an alternative, you might try to use an external tool to format your code (e.g. AStyle). You could create a macro in VS that closes the current file, runs the external tool on the file and re-opens it (and maybe re-positions the cursor at the previous position), so you would be able to format your code from Visual Studio.

I'm not sure if the task is worth the effort, anyway...

Otherwise, you might write your own macro to indent the preprocessor directives in the current file after it has been formatted by VS, without even using external tools (which would probably be rather painful to configure in order to obtain exactly the same formatting as in VS).

Paolo Tedesco
Thank you for information. Actually, I was just curious. I don't plan to invest time in this matter because it's just tiny problem and because the behaviour of Visual Studio may change in future versions - which would make any of my efforts useless :-(
MartyIX
+1  A: 

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 "

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

Hope it helps.

Petar Repac
Thank you! I didn't have time to try to create custom rule but it seems that it would be possible.
MartyIX