Is there any way to disable ReSharper Web Form/MVC (.aspx) Code Formatting on Brace ( } ) Completion?

2.4k Views Asked by At

Is there any way to disable ReSharper Web Form/MVC (.aspx) Code Formatting on Brace ( } ) Completion?

It is really frustrating and most of the time is not what I want. For instance if I have:

<% if (CurrentUser.IsRole(Helper.UserRole.Agent)) { %>
   <%= Html.LinkTo("sign out", SessionRoutes.Logout, null, new { @class = "sign" }) %>
<% } else { %>
   ...
<% } %>

as soon as I type the last <% } it formats like this:

<% if (CurrentUser.IsRole(Helper.UserRole.Agent))
  { %>
 <%= Html.LinkTo("sign out", SessionRoutes.Logout, null, new { @class = "sign" })%>
  <% }
  else
  {%>

  <%
  }%>

I have looked through ReSharper options, but cannot find any setting suitable. It's driving me nuts! To get around it I either have to paste the bracket, sometimes be lucky enough that ctrl+z works or type <{ then insert the % then space :S

I'm sure anybody who has worked with ReSharper and web forms lately will know what I'm talking about.

Thanks

3

There are 3 best solutions below

4
On BEST ANSWER

First, you should change options for braces layout to match your style. Go to ReSharper | Options > Languages > C# > Formatting style > Braces Layout > Braces Layout and change option "Other" to "At end of line (K&R style)".

Next, please note that there is indeed a bug that sometimes causes ReSharper to insert linebreaks after <% or before %>. This bug is fixed in the internal builds and should be in the next EAP (later that 2011-jun-7) as well as in the future 6.0 betas/release.

If you wish you can completely disable auto-format in ReSharper options (but this would affect not only ASP.NET, but regular C# files as well). Go to ReSharper | Options > Editor and switch off Auto-format on semicolon and Auto-format on closing brace.

Hope this helps :)

0
On

Feels like this is a known issue reflected in these two bug reports: http://youtrack.jetbrains.net/issue/RSRP-193396 and http://youtrack.jetbrains.net/issue/RSRP-178877 Please vote for them. Can't guarantee any fix schedule right now but I hope we're able to fix sooner rather than later.

1
On

Are you sure it's Resharper that's doing the formatting? Visual Studio itself also has an "Automatically format completed block on }" option.

Tools | Options > Text Editor > C# > Formatting