Visual Studio 2005/2012: How to keep first curly b

2019-01-13 06:59发布

Trying to get my css / C# functions to look like this:

body {
    color:#222;
}

instead of this:

body 
{
    color:#222;
}

when I auto-format the code.

7条回答
2楼-- · 2019-01-13 07:14

Tools -> Options -> Text Editor -> C# -> Formatting -> New Lines -> New Line Options for braces -> Uncheck all boxes.

查看更多
甜甜的少女心
3楼-- · 2019-01-13 07:26

There is a specific formatting setting in VS 2008/2010 to keep the open brace on the same line:

Click Tools->Options
Select 'CSS' within 'Text Editor' tree node
Select 'Formatting' under 'CSS' node
Click 'Semi-expanded' radio button

You will see a preview what the various radio buttons avail will do to the formatting

查看更多
smile是对你的礼貌
4楼-- · 2019-01-13 07:28

Go to Tools -> Options -> Text Editor -> CSS -> Formatting. Click "Semi-expanded," which matches the style you defined.

Options screen

查看更多
别忘想泡老子
5楼-- · 2019-01-13 07:33

The official MS guidelines (at the time in 2008) tells you to have the curly brace on the same line as the method/property/class and many other things which are not enforced in Visual Studio.

You can change all these auto-text settings under:
Tools -> Options -> Text Editor -> [The language you want to change]

UPDATE: This was based on the book "Framework Design Guidelines" written by some of the core-people from the .NET-team. If you look at the source-code for the likes of ASP.NET MVC, this is no longer accurate.

查看更多
Bombasti
6楼-- · 2019-01-13 07:33

For CSS you'll need the 'Semi Expanded' option.

查看更多
虎瘦雄心在
7楼-- · 2019-01-13 07:33

If you're looking for this option within Visual Studio 2014, then it's under advanced and is now a 'Brace positions' drop down box:

enter image description here

查看更多
登录 后发表回答