I'd like Visual Studio to continue automatically formatting my .cs
files, but is there a way to prevent it auto-formatting C# code in between the <% %>
tags in ASP.NET MVC views because it really makes a mess of it?
views:
79answers:
2
+1
A:
As far as I know there isn't a way to turn off the formatting just in ASP.NET files as it uses the rules for C# in Tools -> Options -> Text Editor -> C#.
zainnab
2010-10-06 00:26:57
Maybe in v.next they'll fix this.
Kev
2010-10-06 08:40:22
+1
A:
Unfortunately (afaik), you can't have separate settings for C# in .cs and .aspx files. You can change the settings for C# in Tools -> Options -> C# -> Formatting.
To get things to work well with MVC, I changed some settings in the New Lines section. I unchecked the boxes for control block, object initializers, and "else". This produces the walk-like-an-egyptian style braces that works best in MVC code, without screwing too much with my normal C# code. I leave the settings for functions, classes etc. alone since you don't normally define those in an .aspx file.
avesse
2010-10-08 18:04:05