Can I make Visual Studio place curly braces on the same line as an if statement (in HTML)?

Visual Studio-2010ViewFormattingCurly Braces

Visual Studio-2010 Problem Overview


In Visual Studio while designing MVC views (in .aspx or .ascx files), I often use if statements. When I auto-format (Ctrl+K+D), Visual Studio wraps the braces in this really ugly and hard to read way:

<% if (Model.UserIsAuthenticated)
    { %>
       (some HTML goes here...)
<% } %>

Is there any way to make Visual Studio auto-format like this instead:

<% if (Model.UserIsAuthenticated) { %>
       (some HTML goes here...)
<% } %>

Or is there a better way to do this? I don't want to use Razor quite yet, but it looks like it would solve my problem. I'm using VS2010 with Resharper 5, if that helps.

Visual Studio-2010 Solutions


Solution 1 - Visual Studio-2010

Under ToolsOptionsText EditorC#FormattingNew Lines are the rules for the open brace on each case (new methods, control blocks, etc), maybe you can find the one you want there.

enter image description here

Solution 2 - Visual Studio-2010

The menu has changed a bit with VS2019.

You can find formatting options by going into
ToolsOptionsText EditorC#Code StyleFormattingNewLines

Formatting options in Visual Stusio 2019

Solution 3 - Visual Studio-2010

In extension to Fleix Martinez's answer:

In mac, 2020 Visual Studio, this is how it is done:

Preferences -> Source Code -> Code Formatting -> C# Source Code -> select C# Format tab

  1. Press Edit enter image description here

  2. Select New Lines from Category

  3. Uncheck all these(choose at your will): enter image description here

Solution 4 - Visual Studio-2010

the formatting is handled by individual plugins, for js you can use the following setting:

// Defines whether an open brace is put onto a new line for functions or not.
"javascript.format.placeOpenBraceOnNewLineForFunctions": true,

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMike ComstockView Question on Stackoverflow
Solution 1 - Visual Studio-2010Felix MartinezView Answer on Stackoverflow
Solution 2 - Visual Studio-2010A-NicoladieView Answer on Stackoverflow
Solution 3 - Visual Studio-2010Daksh GargasView Answer on Stackoverflow
Solution 4 - Visual Studio-2010chantisnakeView Answer on Stackoverflow