问题
I find myself constantly pressing ctrl-z to undo the automatic formatting that happens in templates. For example Resharper would like to format a foreach loop like this:
<%
foreach (var product in Model.Items)
{ %>
<li><%= product.Name %></li>
<% } %>
This is fine in c# code files but it just seems messy in templates. I would prefer to format it like this
<% foreach (var product in Model.Items) { %>
<li><%= product.Name %></li>
<% } %>
回答1:
Open Visual Studio Goto Resharper > Options... > Langauges > C# > Formatting Style > Braces Layout > Other
Change to "At end of line (no space)"
Note this will affect your C# as well.
It is a bit annoying that you cant specify a different code sytle for you aspx pages since its often you do want something differnt.
回答2:
Resharper does not allow you to create custom formatting. You can only change the predefined formatting under options. I poked around and did not see <% %> formatting options. Sorry :(
回答3:
Starting from ReSharper 7.1 (currently at EAP), there is an option to use K&R style in ASP and Razor while continuing to use BSD for C#. ReSharper | Options -> Code Editing | ASP.NET | Editor & Formatting -> Override brace style for C# to always use "At end of line (K&R style)"
来源:https://stackoverflow.com/questions/853671/is-it-possible-to-change-the-way-resharper-4-5-formats-code-in-aspx-ascx-files