Visual Studio Format getter and setter on one line

I just scaffolded a project using Template Studio WinUI v5.3 and when I press Ctrl K D to format document, the getter and setter is placed on new lines.

current.cs

public class MyClass
{
    public string MyProp
    {
        get; set;
    }
}

I want:

public class MyClass
{
    public string MyProp { get; set; }
}

The readability is bad for a class with many properties. I searched a lot through Visual Studio and I still can’t find the solution. The cause I suppose its related to a new C# version. My other projects use the same Visual Studio settings, but this formatting does not apply to them.
Do you know where can I find the setting for this problem?

Problem
I write a prop like this public int MyProperty { get; set; }, then after I press Ctrl K D it moves them on multiline format.

>Solution :

You can set this in your .editorconfig:

[*.cs]
csharp_preserve_single_line_blocks = true

Or you can set it directly in VS: Tools > Options > Text Editor > C# > Code Style > Formatting > Wrapping and check "Leave block on single line".

Image of the above setting

Leave a Reply